Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net not logging debug statements

Tags:

c#

log4net

I am using log4net for the first time and have followed the documentation using supplied configuration samples, however debug statements do not log.

Info, Error, Warn and Fatal levels all log correctly. Can anyone tell me what I am missing?

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>

Some people have mentioned checking AssemblyInfo for [assembly: log4net.Config.XmlConfigurator()], however there is no difference with or without this line.

Logger is declared like:

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

and is accessed like:

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
like image 326
Robert H Avatar asked May 22 '12 17:05

Robert H


People also ask

Does log4net support structured logging?

log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.


1 Answers

You have a filter set to INFO level in your root category (thus filtering out any messages of DEBUG level):

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

Change it to

    <level value="DEBUG" />
like image 128
Péter Török Avatar answered Oct 13 '22 06:10

Péter Török