Debugging log4net

14. March 2015 19:03 by martijn in log4net

Log4net is a great tool but it can be a bit tricky to get working. Adding a debug appender that logs to the visual studio output can be of great help. You can debug log4net by attaching the log4net DebugAppender:

Add a log4net app setting in your app.config file:


<!-- log4net configuration when running in debug mode. -->

<add key="log4net.Internal.Debug" value="true"/>


Add a debug appender in the log4net config:

<appendername="DebugAppender" type="log4net.Appender.DebugAppender">

<immediateFlush value="true"/>

<layout type="log4net.Layout.SimpleLayout"/>


Finally add the appender to the log4net config root:

<level value="ALL"/>
<appender-ref ref="DebugAppender"/>