Reputation: 10055
I've setup the UnhandledException to log any exceptions before my service crashes.
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);
I'm testing this by throwing and unhandled exception.
throw new Exception("TestExcepion");
private void unhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Logs to Log4Net but its not reaching here.
Log.Info("Unhandled Exception: " + (e.ExceptionObject as Exception).ToString());
}
I'm attempting to log this within my unhandledException
method using Log4Net but im getting nothing.
Why isn't the exception being caught?
Upvotes: 4
Views: 4355
Reputation: 19830
It is probably that your throwing code is before use set AppDomain.CurrentDomain.UnhandledException
or because you put it in OnStart
method
Second option is because it is ThreadException
.
Bot above problems were discussed before in following threads:
Upvotes: 4