English 中文(简体)
log4net 没有记录调试语句
原标题:log4net not logging debug statements
  • 时间:2012-05-22 17:03:56
  •  标签:
  • c#
  • log4net

我首次使用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, 以便[ 组装: log4net. Config. XmlConfigurator ()], 但无论是否使用这条线, 都没有任何区别 。

Logger 被宣布为 :

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 级别( 从而过滤任何 < code> DEBUG 级别的信件 ):

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

换成

    <level value="DEBUG" />
问题回答

对log4net 水平按以下顺序界定:

ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF

基于您当前的设置, 您正在与 INFO 和下面写入一切 。

将您的根节点设定为如下:

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

在您的节点中将级别值更改为“ DEBUG ”...

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




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签