• .net core 集成lognet4


    1. nuget 安装  Microsoft.Extensions.Logging.Log4Net.AspNetCore

    2.修改

      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>().ConfigureLogging((hostingContext, logging) =>
                    {
                        //I assumed if clearing the providers, may clear the filter configuration, but it turned out it doesnt matter.
                        logging.ClearProviders();
                        logging.SetMinimumLevel(LogLevel.Error);
                        //This won't work, no matter that you properly have configured everything.
                        //logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
    
                        logging.AddFilter("Default", LogLevel.Error);
                        logging.AddFilter("Microsoft", LogLevel.Error);
                        logging.AddFilter("System", LogLevel.Error);
                        //I'm adding the debug provider, just so we can compare, in production you can exclude it.
                        logging.AddDebug();
                        logging.AddConsole();
                        logging.AddLog4Net();
                    });

    3.项目根目录添加log4net.config配置文件

    <?xml version="1.0" encoding="utf-8" ?>
    <log4net>
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
        <file value="App_Data/Logs/Logs.txt" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="10" />
        <maximumFileSize value="10000KB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
        </layout>
      </appender>
      <root>
        <appender-ref ref="RollingFileAppender" />
        <level value="ERROR" />
      </root>
    </log4net>
  • 相关阅读:
    Python中变量的作用域
    Python中关于函数的介绍
    python列表中的赋值与深浅拷贝
    Python中关于集合的介绍及用法
    python中文件操作的六种模式及对文件某一行进行修改的方法
    python中文件操作的其他方法
    python中文件操作的基本方法
    python中字符串的一些用法
    python里字典的用法介绍
    小谈python里 列表 的几种常用用法
  • 原文地址:https://www.cnblogs.com/lkd3063601/p/12155322.html
Copyright © 2020-2023  润新知