• 【log4net】配置


    第一步在 AssemblyInfo  添加如下代码

    第二步:在web.config添加如下代码:

    <log4net>
    
        <root>
          <level value="all" />
          <appender-ref ref="INFOAppender" />
          <appender-ref ref="DEBUGAppender" />
          <appender-ref ref="WARNAppender" />
          <appender-ref ref="ERRORAppender" />
          <appender-ref ref="FATALAppender" />
          <appender-ref ref="ColoredConsole" />
          <appender-ref ref="TraceAppender" />
        </root>
    
        <appender name="INFOAppender" type="log4net.Appender.RollingFileAppender">
          <file value="logs\info\" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <datePattern value="yyyyMMdd'.log'" />
          <staticLogFileName value="false" />
          <maxSizeRollBackups value="100" />
          <maximumFileSize value="10MB" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="INFO" />
            <param name="LevelMax" value="INFO" />
          </filter>
        </appender>
        <appender name="DEBUGAppender" type="log4net.Appender.RollingFileAppender">
          <file value="logs\debug\" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <datePattern value="yyyyMMdd'.log'" />
          <staticLogFileName value="false" />
          <maxSizeRollBackups value="100" />
          <maximumFileSize value="10MB" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG" />
            <param name="LevelMax" value="DEBUG" />
          </filter>
        </appender>
        <appender name="WARNAppender" type="log4net.Appender.RollingFileAppender">
          <file value="logs\warn\" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <datePattern value="yyyyMMdd'.log'" />
          <staticLogFileName value="false" />
          <maxSizeRollBackups value="100" />
          <maximumFileSize value="10MB" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="WARN" />
            <param name="LevelMax" value="WARN" />
          </filter>
        </appender>
        <appender name="ERRORAppender" type="log4net.Appender.RollingFileAppender">
          <file value="logs\error\" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <datePattern value="yyyyMMdd'.log'" />
          <staticLogFileName value="false" />
          <maxSizeRollBackups value="100" />
          <maximumFileSize value="10MB" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="ERROR" />
            <param name="LevelMax" value="ERROR" />
          </filter>
        </appender>
        <appender name="FATALAppender" type="log4net.Appender.RollingFileAppender">
          <file value="logs\fatal\" />
          <appendToFile value="true" />
          <rollingStyle value="Composite" />
          <datePattern value="yyyyMMdd'.log'" />
          <staticLogFileName value="false" />
          <maxSizeRollBackups value="100" />
          <maximumFileSize value="10MB" />
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
          <filter type="log4net.Filter.LevelRangeFilter">
            <param name="LevelMin" value="FATAL" />
            <param name="LevelMax" value="FATAL" />
          </filter>
        </appender>
    
        <!--调试模式,输出日志到控制台-->
        <appender name="ColoredConsole" type="log4net.Appender.ColoredConsoleAppender">
          <mapping>
            <level value="ERROR" />
            <foreColor value="Red, HighIntensity" />
            <!--<backColor value="Green" />-->
          </mapping>
          <mapping>
            <level value="DEBUG" />
            <foreColor value="Yellow, HighIntensity" />
            <backColor value="Green" />
          </mapping>
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
          </layout>
        </appender>
        <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
          <layout type="log4net.Layout.PatternLayout">
            <param name="conversionPattern" value="%newline*******************************************%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline*******************************************%newline" />
          </layout>
        </appender>
    
      </log4net>

    相关的log文件添加在根目录中记得:

    第三:添加如下代码:记得引入log4net 

     第四:

    得到的效果如下:

  • 相关阅读:
    带提示范围的猜数小游戏--python
    python中字符串的常见操作
    html表单相关标签及属性
    CSS常用属性
    python装饰器
    python闭包的概念及使用
    nuxt.js实战踩坑记录
    vuex填坑记录
    prerender-spa-plugin预处理vue项目实践
    node+express第一次实战踩坑记录
  • 原文地址:https://www.cnblogs.com/huchaoheng/p/5653576.html
Copyright © 2020-2023  润新知