public partial class PaintingLineDbContext : DbContext { // 输出到Console public static readonly LoggerFactory LoggerFactory = new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) }); protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (env == "Development") { optionsBuilder.UseLoggerFactory(LoggerFactory); } }
}
supervisor配置文件:api.ini
[program:api] command=dotnet21 OpenAuth.PaintLine.WebApi.dll directory=/app/api environment=ASPNETCORE__ENVIRONMENT=Production user=root stopsignal=INT autostart=true autorestart=true startsecs=1 stderr_logfile=/var/log/api.err.log stdout_logfile=/var/log/api.out.log
.net core 2.1 + keepalived部署的时候,一直在往/var/log/api.out.log写文件,经过排查发现:
不知道哪位大哥加了这么一段代码 optionsBuilder.UseLoggerFactory(LoggerFactory); ,导致entityframework大量输出日志级别为debug和info的信息,进而导致supervisor一直疲于往文件写日志。然后我的服务器CPU就爆满了。