log4net: what am I doing wrong?

Posted by Berryl on Stack Overflow See other posts from Stack Overflow or by Berryl
Published on 2010-05-08T16:42:47Z Indexed on 2010/05/08 16:48 UTC
Read the original article Hit count: 508

Filed under:

Being a log4net newb / boob I just copied lines from an NHibernate example project where I can see the log.txt file is updated. Is there a quick answer why mine isn't creating the file?

Cheers,
Berryl

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

I saw another post here saying this should go in AssemblyInfo, but in the example project this is just another line in a static helper class. Not wanting to 'mess with' assemblyInfo I also put this in a static helper, along with the following to actually log in the same static helper class:

private static readonly log4net.ILog _log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );

And in app.config, I have

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

    <!-- This section contains the log4net configuration settings -->
<log4net>
    <!-- Define an output appender (where the logs can go) -->
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
        <param name="File" value="log.txt" />
        <param name="AppendToFile" value="false" />
        <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
        </layout>
    </appender>
    <appender name="LogDebugAppender" type="log4net.Appender.DebugAppender, log4net">
        <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/>
        </layout>
    </appender>

    <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
    <root>
        <priority value="ALL" />
        <appender-ref ref="LogFileAppender" />
        <appender-ref ref="LogDebugAppender"/>
    </root>

    <!-- Specify the level for some specific namespaces -->
    <!-- Level can be : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
    <logger name="NHibernate">
        <level value="ALL" />
    </logger>
</log4net>

© Stack Overflow or respective owner

Related posts about log4net