gpt4 book ai didi

c# - log4net 彩色控制台不工作

转载 作者:行者123 更新时间:2023-12-02 21:02:18 25 4
gpt4 key购买 nike

我将 log4net 用于两个不同的日志文件和彩色控制台,这些文件工作正常,但控制台始终为空。

在我的app.config中

  <log4net>
<root>
<priority value="ALL" />
<appender-ref ref="ConsoleOutAppender" />
<appender-ref ref="PortalLoggerAppender" />
<appender-ref ref="ApplicationLoggerAppender" />
</root>

<appender name="ConsoleOutAppender" type="log4net.Appender.ColoredConsoleAppender">
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="ApplicationLogger" />
</filter>
<mapping>
<level value="ERROR" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow, HighIntensity" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="Cyan" />
</mapping>
<mapping>
<level value="DEBUG" />
<foreColor value="Green" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd/MM HH:mm:ss} [%level] %newline%message%newline" />
</layout>
</appender>

<appender name="PortalLoggerAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Results/PortalLog_%property{DateTime}_app.log" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="PortalLogger" />
</filter>
<encoding value="utf-8" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="20MB" />
<countDirection value="1" />
<datePattern value="yyyyMMdd" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd/MM HH:mm:ss} [%level] %newline%message%newline" />
</layout>
</appender>

<appender name="ApplicationLoggerAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Results/ApplicationLog_%property{DateTime}_app.log" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="ApplicationLogger" />
</filter>
<encoding value="utf-8" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="20MB" />
<countDirection value="1" />
<datePattern value="yyyyMMdd" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd/MM HH:mm:ss} [%level] %newline%message%newline" />
</layout>
</appender>

<logger name="PortalLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="PortalLoggerAppender"/>
</logger>

<logger name="ApplicationLogger" additivity="false">
<level value="ALL"/>
<appender-ref ref="ApplicationLoggerAppender"/>
</logger>


</log4net>

知道为什么 log4net 没有打印到控制台吗?我希望应用程序记录器也将写入控制台中。提前谢谢您。

最佳答案

您已将 additivity 专门设置为 false,这 as per the docs意味着:

the appenders found in the ancestors of this logger are not used

这意味着在顶部 root 中配置的内容将被忽略。删除 additivity 或将其设置为 true(默认值),或者也将控制台附加程序显式添加到此记录器。

关于c# - log4net 彩色控制台不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com