It seems that Log4Net silently shuts down for reasons that are not obvious, and I'm at a loss how to troubleshoot it. My hunch is that a particular appender is failing on a specific log message and that seems to shut down the whole stack.
Is there a way to get Log4Net to throw an exeception (at least during our debug phase) rather than a slient shutting down of the service.
How do I completely disable all logging at runtime? Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF".
log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary.
Expanding on the previous answer -
To add a trace listener for the log4net.Internal.Debug trace, add this to your app config:
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\temp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
Replace the initializeData attribute value above with your desired log file path. Be sure the application or ASP.NET server process has permission to write to this file.
Another thing you can do is inspect the messages that are returned from the log4net configuration on startup. As of log4net version 1.2.11, the XmlConfigurator.Configure() methods return an ICollection containing strings listing problems encountered during the configuration process.
So if you've got something like this:
XmlConfigurator.Configure();
change it to
ICollection configMessages = XmlConfigurator.Configure();
and inspect configMessages in a debugger, or print them out somewhere, e.g.
foreach (string msg in configMessages)
{
Console.WriteLine(msg);
}
If all else fails, download the log4net source, add the project to your solution, and reference the project instead of log4net.dll. Now you can step into the log4net calls in the debugger.
I think there's a config value you can put in the appSettings section of your app.config/web.config to turn on internal debug statements in log4net:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
This will give you some insight into any errors that log4net might be swallowing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With