zoukankan      html  css  js  c++  java
  • .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>
  • 相关阅读:
    rest-framework之路由
    rest-framework之频率控制
    mysql 模糊查询 concat()
    解决spring使用动态代理
    MySQL巧用sum,case...when...优化统计查询
    解决maven项目中有小红叉的问题
    google ---gson字符串数组用GSON解析然后用逗号隔开拼接,去掉最后一个逗号
    Elicpse使用技巧-打开选中文件文件夹或者包的当前目录
    powdesigner建表
    遍历map
  • 原文地址:https://www.cnblogs.com/lkd3063601/p/12155322.html
Copyright © 2011-2022 走看看