zoukankan      html  css  js  c++  java
  • 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就爆满了。

  • 相关阅读:
    如何根据关键字匹配度排序
    LeetCode 题解目录
    Spring Boot、Cloucd 学习示例
    JavaScript工具库
    使用 Docker 部署 Spring Boot 项目
    LeetCode 寻找两个有序数组的中位数
    Bean 生命周期
    Dubbo支持的协议
    MySQL组成模块
    Spring Boot 搭建TCP Server
  • 原文地址:https://www.cnblogs.com/subendong/p/15600125.html
Copyright © 2011-2022 走看看