2016-12-19 1 views
0

log4net을 구성하여 처리되지 않은 예외를 기록하고 싶습니다. 설정 파일 만 변경하여이 작업을 수행 할 수 있습니까? 그렇다면 어떻게해야합니까? 그렇지 않은 경우 코드를 구현하려면 어떻게해야합니까?처리되지 않은 예외를 기록하도록 Log4Net을 구성하는 방법

+0

다른 유형의 앱에는 처리되지 않은 예외 처리기를 설정하는 여러 가지 방법이 있습니다. 그런 다음 예외를 log4net에 로그하는 데 사용할 수 있습니다 – stuartd

답변

0

구성만으로는이 작업을 수행 할 수 없으므로 어딘가에 실제 예외를 기록해야합니다. 따라서 '발견되지 않은'예외를 잡아서 기록해야합니다.

public static void Main(string[] args) 
{ 
    // Add the event handler for handling UI thread exceptions to the event. 
    Application.ThreadException += new  
    ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException); 

    // Set the unhandled exception mode to force all Windows Forms errors 
    // to go through our handler. 
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 

    // Add the event handler for handling non-UI thread exceptions to the event. 
    AppDomain.CurrentDomain.UnhandledException += new  
    UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 
} 

핸들러에서 log4net에 로그온 할 수 있습니다. 그런 다음 구성을 사용하여 스위치를 켜고 끌 수 있습니다.

그러나 예외가 catch되지 않는 경우가 있습니다. 예를 들어 failfast가 호출 될 때.

관련 문제