我是第一次使用log4net,并使用提供的配置示例跟踪文档,但是调试语句不记录。
信息,错误,警告和致命级别都正确记录。谁能告诉我我失踪了什么?
app.config:
<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>
有人提到为[assembly:log4net.Config.XmlConfigurator()]检查AssemblyInfo,但是这行没有差别。
记录器声明如下:
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
答案 0 :(得分:17)
您的根类别中的过滤器设置为INFO
级别(从而过滤掉DEBUG
级别的所有邮件):
<root>
<level value="INFO" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
将其更改为
<level value="DEBUG" />
答案 1 :(得分:12)
log4net级别按以下顺序定义:
ALL, DEBUG, 信息, 警告, 错误, 致命, OFF
根据您当前的设置,您使用INFO及以下内容编写所有内容。
将根节点设置为以下内容:
<root>
<level value="DEBUG" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
答案 2 :(得分:8)
将节点中的级别值更改为“DEBUG”...
<root>
<level value="DEBUG" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>