zoukankan      html  css  js  c++  java
  • C# log4net日志

    引用log4net.dll库

    [log4net.dll库下载地址][1]

    AssemblyInfo.cs

    最后一行添加如下代码:

    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension = "config", Watch = true)]

    log4net.config

    注意把这个文件的属性”复制到输出目录”值改为”始终复制”, 不然会不生效

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
    
      <log4net>
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <param name= "File" value= "D:App_Logservicelog"/>
          <param name= "AppendToFile" value= "true"/>
          <param name= "MaxSizeRollBackups" value= "10"/>
          <param name= "StaticLogFileName" value= "false"/>
          <param name= "DatePattern" value= "yyyy-MM-dd&quot;.read.log&quot;"/>
          <param name= "RollingStyle" value= "Date"/>
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="[%date]-[%thread]-[%-p]-[%logger]-[%M] -> %message%newline" />
          </layout>
        </appender>
    
        <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
          <mapping>
            <level value="DEBUG" />
            <foreColor value="Red, HighIntensity" />
          </mapping>
          <mapping>
            <level value="DEBUG" />
            <foreColor value="Green" />
          </mapping>
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%n%date{HH:mm:ss,fff} [%-5level] %m" />
          </layout>
    
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="Info" />
            <param name="LevelMax" value="Fatal" />
          </filter>
        </appender>
    
        <root>
          <level value="all" />
          <appender-ref ref="ColoredConsoleAppender"/>
          <appender-ref ref="RollingLogFileAppender"/>
        </root>
      </log4net>
    </configuration>

    应用

    private static ILog log = LogManager.GetLogger(typeof(Program));
    [STAThread]
    static void Main(string[] args)
    {
        log.Info("info");
        log.Debug("Debug");
        log.Error("Error");
    }

    https://segmentfault.com/a/1190000012601876
  • 相关阅读:
    Jmeter断言设置
    jmeter设置自动启动时间
    jmeter用命令行运行jmx脚本
    jmeter多用户并发压力测试(导入文件)
    Fiddler导出接口抓包数据
    postman和postwoman
    UVa10561
    UVa11859
    Ferguson游戏
    UVa11916
  • 原文地址:https://www.cnblogs.com/xihong2014/p/13675008.html
Copyright © 2011-2022 走看看