log4net配置与初始化

1、配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <logger name="Weixin" additivity="false">
      <level value="All" />
      <appender-ref ref="AccountRollingFileAppender" />
    </logger>
    <appender name="AccountRollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Logs\Weixin.log" />
      <param name="AppendToFile" value="true" />
      <param name="RollingStyle" value="Size" />
      <param name="CountDirection" value="1" />
      <param name="MaximumFileSize" value="1MB" />
      <param name="MaxSizeRollBackups" value="1024" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>
  </log4net>
</configuration>
 
2、初始化:
            string logConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log4Net.config");
            XmlConfigurator.Configure(new FileStream(logConfigPath, FileMode.Open));
posted @ 2016-09-05 20:06  GUOKUN  阅读(1904)  评论(0编辑  收藏  举报