2013-09-03 2 views
3

서비스가 중단되기 전에 예외를 기록하도록 UnhandledException을 설정했습니다.Windows 서비스에서 CurrentDomain.UnhandledException이 발생하지 않습니다.

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 메서드 내에서이 로그온을 시도하고있어하지만 메신저 아무것도를 받고 없습니다.

예외가 잡히지 않는 이유는 무엇입니까?

+0

코드의 포스트 더. –

답변

3

이 사용 AppDomain.CurrentDomain.UnhandledException을 설정하기 전에 던지는 코드는 것을 아마 또는 OnStart 방법에 넣어 있기 때문에 ThreadException 때문에

두 번째 옵션입니다. 문제 위의

봇은 다음 스레드에서 이전에 논의되었다 : 여기

  1. How can I set up .NET UnhandledException handling in a Windows service?
  2. Global exception handler for windows services?
+0

빙고. 나는 그것을 OnStart 메소드에 넣을 것이다. 감사. – CathalMF

+0

덕분에 고맙게 생각하지 않아도됩니다. 위의 대답은 –

+0

입니다.'ThreadException'은 Windows Forms에만 해당되며 Windows 서비스에는 적용되지 않습니다 (http://stackoverflow.com/a/2014684/8479). – Rory

관련 문제