C# Windows服务中未引发CurrentDomain.UnhandledException
我已经设置了UnhandledException,以便在服务崩溃之前记录任何异常C# Windows服务中未引发CurrentDomain.UnhandledException,c#,unhandled-exception,C#,Unhandled Exception,我已经设置了UnhandledException,以便在服务崩溃之前记录任何异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException); 我正在通过抛出未处理的异常来测试这一点 throw new Exception("TestExcepion"); private void unhandledException(object sender, U
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);
我正在通过抛出未处理的异常来测试这一点
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());
}
我正试图用Log4Net在我的unhandledException
方法中记录这个,但我什么也没有得到
为什么没有捕获异常?可能是因为您的抛出代码在使用set
AppDomain.CurrentDomain.UnhandledException
之前,或者是因为您将其放入了OnStart
方法中
第二个选项是因为它是ThreadException
之前在以下线程中讨论了上述问题:
在这里发布更多代码。宾果。我把它放在OnStart方法中。谢谢。
ThreadException
特定于Windows窗体,不适用于Windows服务()。