gpt4 book ai didi

c# - log4net 不记录调试语句

转载 作者:可可西里 更新时间:2023-11-01 08:51:09 25 4
gpt4 key购买 nike

我是第一次使用 log4net 并使用提供的配置示例遵循文档,但是调试语句不记录。

信息、错误、警告和致命级别都正确记录。谁能告诉我我错过了什么?

应用程序配置:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

<log4net>
<appender name="Console" type="log4net.Appender.ColoredConsoleAppender">

<mapping>
<level value="INFO" />
<foreColor value="Green"/>
</mapping>

<mapping>
<level value="DEBUG" />
<foreColor value="Cyan,HighIntensity"/>
</mapping>

<mapping>
<level value="WARN" />
<foreColor value="Purple,HighIntensity"/>
</mapping>

<mapping>
<level value="ERROR" />
<foreColor value="Red,HighIntensity"/>
</mapping>

<mapping>
<level value="FATAL" />
<foreColor value="Yellow,HighIntensity"/>
</mapping>

<layout type="log4net.Layout.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
</layout>
</appender>

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="example.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %thread %logger - %message%newline" />
</layout>
</appender>

<root>
<level value="INFO" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</log4net>

有些人提到检查 AssemblyInfo for [assembly: log4net.Config.XmlConfigurator()],但是有或没有这一行没有区别。

记录器声明如下:

private static readonly ILog log = LogManager.GetLogger( typeof( CWD_Netsuite ) );

访问方式如下:

XmlConfigurator.Configure();
log.Debug("Debugging"); //does not get logged
log.Info( "Entering Application" ); //logged to console and log file
log.Debug( "Debug Statement" ); //does not get logged

log.Error( "Error statement" ); //logged to console and log file
log.Warn( "Warning statement" ); //logged to console and log file
log.Fatal( "Fatal Statement" ); //logged to console and log file

最佳答案

您在根类别中将过滤器设置为 INFO 级别(从而过滤掉所有 DEBUG 级别的消息):

<root>
<level value="INFO" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>

改成

    <level value="DEBUG" />

关于c# - log4net 不记录调试语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706670/

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