log4.net 配置-控制台输出带颜色的日志

一般对控制台输入的日志我们使用的 Appender 为 ConsoleAppender ,日志为白色文字。

当我们想到 DEBUG,INFO,WARN,ERROR  每种日志设置一种颜色时我们需要将 Appender 改为 ColoredConsoleAppender 

然后增加相应的颜色配置

 <appender name="ConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
      <mapping>
        <level value="ERROR" />
        <foreColor value="Red, HighIntensity" />
      </mapping>
      <mapping>
        <level value="Warn" />
        <foreColor value="Yellow,HighIntensity" />
      </mapping>
      <mapping>
        <level value="Info" />
        <foreColor value="White" />
      </mapping>
      <mapping>
        <level value="Debug" />
        <foreColor value="Purple, HighIntensity" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>

颜色的值可以为

Blue
Green
Red 
White 
Yellow
Purple 
Cyan 
HighIntensity 

 

posted @ 2018-06-27 11:14  jgjg2323  阅读(3436)  评论(0编辑  收藏  举报