views:

242

answers:

1

I use log4net all the time, but one thing I've never figured out is how to tell what's going on on the inside. For example, I've got a console appender and a database appender in my project. I made a few changes to the database and the code, and now the database appender doesn't work anymore. I'll figure out why eventually, but it would help a lot if I could see what's going on inside log4net.

Does log4net generate any kind of output that I can view to try to determine the source of my problem?

+1  A: 

First you have to set this value on the application configuration file:

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

Then, to determine the file in which you want to save the output you can add the following code in the same .config file:

<configuration>
...

<system.diagnostics>
    <trace autoflush="true">
        <listeners>
            <add 
                name="textWriterTraceListener" 
                type="System.Diagnostics.TextWriterTraceListener" 
                initializeData="C:\tmp\log4net.txt" />
        </listeners>
    </trace>
</system.diagnostics>

...
</configuration>

You can find a more detailed explanation looking for 'How do I enable log4net internal debugging?' in the log4net FAQ page:

http://logging.apache.org/log4net/release/faq.html

despart