log4net在WPF中的配置

app.config:

<configSections>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

 

<log4net debug="true">
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="logs\log.txt"/>
    <appendToFile value="true"/>
    <rollingStyle value="Size"/>
    <maxSizeRollBackups value="10"/>
    <maximumFileSize value="10MB"/>
    <staticLogFileName value="true"/>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n"/>
    </layout>
  </appender>
  <root>
    <level value="DEBUG"/>
    <appender-ref ref="RollingLogFileAppender"/>
  </root>
</log4net>

 

app.xaml:(构造函数中)

  log4net.Config.XmlConfigurator.Configure();

 

初始化:(主程序中)

  ILog l = log4net.LogManager.GetLogger("mainClass");

 

记录日志:

  l.Error("aaa");

 

完成。

posted @ 2020-12-10 16:58  jasonlai2016  阅读(370)  评论(0编辑  收藏  举报