log4Net 简单配置实用

技术分享
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
View Code
技术分享
  <log4net debug="false">
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
      <!--日志存放位置-->
      <param name="File" value="c:\ResourceMgrLog\" />
      <param name="datePattern" value="yyyy-MM-dd HH:mm" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="10" />
      <param name="MaximumFileSize" value="5MB" />
      <param name="StaticLogFileName" value="false" />
      <param name="DatePattern" value="yyyy-MM-dd.LOG" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <!--日志存放位置-->
      <param name="File" value="C:\ResourceMgrLog\" />
      <param name="AppendToFile" value="true" />
      <param name="StaticLogFileName" value="false" />
      <param name="DatePattern" value="yyyy-MM-dd.LOG" />
      <param name="MaxSizeRollBackups" value="10" />
      <param name="MaximumFileSize" value="5MB" />
      <param name="RollingStyle" value="Date" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="RollingLogFileAppender" />
    </root>
  </log4net>
View Code

Global.asax中的 Application_Start方法下添加:

log4net.Config.XmlConfigurator.Configure();
 private static readonly ILog log = LogManager.GetLogger(typeof(FixedAssetManagement));

log.Debug("",ex);

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。