码迷,mamicode.com
首页 > 其他好文 > 详细

log4N配置方式

时间:2016-06-23 22:14:34      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

方式一、

  

  <log4net>
    <!-- 启动日志 -->
    <appender name="PayAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="../Logs/Haier.Design.Web/Pay.log"></param>
      <param name="AppendToFile" value="true"></param>
      <param name="MaxSizeRollBackups" value="10"></param>
      <param name="MaximumFileSize" value="5MB"></param>
      <param name="RollingStyle" value="Size"></param>
      <param name="StaticLogFileName" value="true"></param>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d - %m%n"></param>
      </layout>
    </appender>
    <category name="Pay.Loger">
      <priority value="DEBUG"></priority>
      <appender-ref ref="PayAppender"></appender-ref>
    </category>
    <!--异常日志-->
    <appender name="LogAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="../Logs/Haier.Design.Web/"></param>
      <param name="AppendToFile" value="true"></param>
      <param name="MaxSizeRollBackups" value="10"></param>
      <param name="MaximumFileSize" value="3MB"></param>
      <param name="RollingStyle" value="Size"></param>
      <rollingStyle value="Date" />
      <datePattern value="yyyy-MM-dd&quot;.log&quot;" />
      <param name="StaticLogFileName" value="false"></param>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d(%p) %F(%L)%n %m%n"></param>
      </layout>
    </appender>
    <category name="Logerror">
      <priority value="ERROR|DEBUG"></priority> 
      <appender-ref ref="LogAppender"></appender-ref>
    </category>
  </log4net>

 

方式二、

  

<log4net>
    <logger name="logerror">
      <level value="ALL" />
      <appender-ref ref="ErrorAppender" />
    </logger>
    <logger name="loginfo">
      <level value="ALL" />
      <appender-ref ref="InfoAppender" />
    </logger>
    <appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Log//LogError//" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="100" />
      <param name="MaxFileSize" value="10240" />
      <param name="StaticLogFileName" value="false" />
      <param name="DatePattern" value="yyyy//yyyyMM//yyyyMMdd-hh‘.txt‘" />
      <param name="RollingStyle" value="Date" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline %n====================================== %n记录时间:%date %n线程ID:[%thread] %n日志级别:%-5level %n出错类:%logger property: [%property{NDC}]  %n错误描述:%n%message %newline %n--------------------------------------%n"/>
      </layout>
    </appender>
    <appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Log//LogInfo//" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="100" />
      <param name="MaxFileSize" value="10240" />
      <param name="StaticLogFileName" value="false" />
      <param name="DatePattern" value="yyyy//yyyyMM//yyyyMMdd-hh‘.txt‘" />
      <param name="RollingStyle" value="Date" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline %n====================================== %n记录时间:%date %n线程ID:[%thread] %n日志级别:%-5level %n出错类:%logger property: [%property{NDC}]  %n错误描述:%n%message %newline %n--------------------------------------%n"/>
      </layout>
    </appender>
  </log4net> 

 

log4N配置方式

标签:

原文地址:http://www.cnblogs.com/ismallboy/p/5612253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!