• keepalived + asp.net core2.1 + entityframework + 禁用console


        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就爆满了。

  • 相关阅读:
    Undo/Redo的C#实现方式
    c#中@符号作用
    面向对象理解随笔
    C# 面向对象定义常量,属性,方法
    c# 字段和属性
    面向对象思想
    用C表达面向对象语言的机制——C#版
    判断生日
    查找字符
    被7整除
  • 原文地址:https://www.cnblogs.com/subendong/p/15600125.html
Copyright © 2020-2023  润新知