Blog Post

Debugging Issues With Log4Net Not Logging

,

When you find log4net is not writing anything to your logs it can be a pain to debug as obviously Log4Net will (and should) never throw an exception.

The first thing you want to do when you find you have this problem is to enable tracing in Log4Net. This is done by adding the following key to your app settings in either your app.config or web.config

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

This tells Log4Net to write a trace. Next you need to turn on tracing for the application as without this Log4Net has nothing to write the trace information to. This is done by adding the following to either your app.config or web.config

<trace autoflush="true">
  <listeners>
    <add
      name="textWriterTraceListener"
      type="System.Diagnostics.TextWriterTraceListener"
      initializeData="appTrace.txt" />
  </listeners>
</trace>

When you then run the application any traces will be written to the applications running directory in a file called appTrace.txt. You can easily specify any path you want as long as the application has permission to write to this path. With any luck after a quick run of your application through code that should write to the log file you should have enough information in the trace file to work out why nothing is getting logged.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating