keepalived + asp.net core2.1 + entityframework + 禁用console
阿新 • • 發佈:2021-11-24
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就爆滿了。