log4net配置详细说明

1.web网站中创建log4net.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="log/log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="1000" />
      <maximumFileSize value="1024KB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
      <filter type="log4net.Filter.LevelMatchFilter">
        <param name="LevelToMatch" value="INFO" />
      </filter>
    </appender>
    <appender name="RollingErrorFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="log/error_log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="1000" />
      <maximumFileSize value="1024KB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="WARN" />
        <levelMax value="FATAL" />
      </filter>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
    <logger name="AccountInfoLogger">
      <appender-ref ref="RollingFileAppender"/>
      <appender-ref ref="RollingErrorFileAppender"/>
      <level value="INFO"/>
    </logger>
  </log4net>
  
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>

</configuration>
2.调用日志的类库或web的AssemblyInfo.cs中添加组件

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

3.调用

logger.Error("", ex);

 

分类: C# Asp.net

本文转自快乐就好博客园博客,原文链接:http://www.cnblogs.com/happyday56/p/3543490.html,如需转载请自行联系原作者
上一篇:maven命令发布到tomcat


下一篇:php防止页面刷新重复提交数据