Pregunta

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?

¿Fue útil?

Solución

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:

  1. How can I set up .NET UnhandledException handling in a Windows service?
  2. Global exception handler for windows services?
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top