日志管理

采用log4net+Common.Logging.Log4Net

1、Nuget:Common.Logging.Log4Net208 自动下载完四个包

2、配置config 

Common:

<sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>

<!--与log4net关联-->
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net208">
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/Conf/log4net.config" />
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>

Log4net:log4net.config

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

<root>
<level value="ALL"/>
<appender-ref ref="LogFileAppender"/>
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="my_log-file.txt"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>

</layout>

</appender>

<logger name="yateJob" additivity="false" >
<level value="ALL" />
<appender-ref ref="yateJobTxtAppender" />
</logger>
</log4net>
</configuration>

 log4初始化:log4net.Config.XmlConfigurator.Configure();

3、扩展

posted @ 2018-09-15 21:39  雄鹰低飞  阅读(105)  评论(0编辑  收藏  举报