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);

 

你可能感兴趣的:(log)