log4net的典型配置

Author: Kagula

日期:2015-06-16

环境:

[1]VS2010SP1

[2]log4net-1.2.13


在VS2010SP1中,项目的“Target Framework”默认为“.Net Framework 4 Client Profile”得改为“.Net Framework 4”。

否则Add Reference后,log4net名字空间还是经常会找不到。


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <!--日志记录组建配置-->
  <log4net>
    <!--Visual Studio output窗口输出-->
    <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger:%L - %message%newline%exception"/>
      </layout>
    </appender>
    <!--当前应用程序目录的Logs子目录  -->
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <file value="Logs\log_" />
      <datePattern value="yyyy.MM.dd'.log'" />
      <staticLogFileName value="false" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="5MB" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger:%L - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="TraceAppender"/>
      <appender-ref ref="RollingFileAppender"/>
    </root>
  </log4net>
</configuration>


参考资料

[1]《将Log4net的配置配置到的独立文件中》

http://www.cnblogs.com/zfanlong1314/p/3662679.html


你可能感兴趣的:(log4net的典型配置)