log4N配置方式

Posted ismallboy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了log4N配置方式相关的知识,希望对你有一定的参考价值。

方式一、

  

  <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配置方式的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段11——vue路由的配置

VSCode自定义代码片段11——vue路由的配置

VSCode自定义代码片段11——vue路由的配置

VS Code配置markdown代码片段

VS Code配置markdown代码片段

从零开始配置vim(27)——代码片段