log4net

  1. 引用log4net.dll
  2. AssemblyInfo.cs文件添加:[assembly: log4net.Config.XmlConfigurator(ConfigFile = "configs/log4net.config", Watch = true)](log4net配置文件单独放置)
  3. Global全局文件中添加:log4net.Config.XmlConfigurator.Configure();
  4. web.config中添加log4net节点
    1. <configSections>    
        <section name="log4net" allowLocation="true" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
      </configSections>

       

  5. log4net.config文件(例如:)
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      
      <configSections>
        <section name="log4net" allowLocation="true" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
      </configSections>
      
      <log4net>
        
        <root>
          <level value="DEBUG" />
          <appender-ref ref="RollingLogFileAppender" />
        </root>
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <param name="File" value="log/log-"/>
          <param name="AppendToFile" value="true"/>
          <param name="MaxSizeRollBackups" value="10"/>
          <param name="MaximumFileSize" value="10MB"/>
          <param name="StaticLogFileName" value="false"/>
          <param name="DatePattern" value="yyyyMMdd&quot;.log&quot;"/>
          <param name="RollingStyle" value="Date"/>
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d  [%t]  %-5p  %c  [%x]  -  %m%n"/>
          </layout>
        </appender>   
      </log4net>
    </configuration>

     

 

     

 

posted @ 2016-07-12 10:20  随学·笔记  阅读(123)  评论(0编辑  收藏  举报