首页 > 代码库 > log4net配置与初始化

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="http://www.mamicode.com/All" />
      <appender-ref ref="AccountRollingFileAppender" />
    </logger>
    <appender name="AccountRollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="http://www.mamicode.com/Logs/Weixin.log" />
      <param name="AppendToFile" value="http://www.mamicode.com/true" />
      <param name="RollingStyle" value="http://www.mamicode.com/Size" />
      <param name="CountDirection" value="http://www.mamicode.com/1" />
      <param name="MaximumFileSize" value="http://www.mamicode.com/1MB" />
      <param name="MaxSizeRollBackups" value="http://www.mamicode.com/1024" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="http://www.mamicode.com/%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));

log4net配置与初始化