How to log all thrown exceptions?

前端 未结 8 2070
一个人的身影
一个人的身影 2020-11-29 07:55

How to log any exceptions that were thrown and catched? Something like Visual Studio\'s IntelliTrace do. Or is there a way to integrate InteliTrace into debug version of app

8条回答
  •  清歌不尽
    2020-11-29 08:43

    I guess the feature you are searching for is called FirstChanceException and can be accessed via the AppDomain.FirstChanceException Event

    Essentially this event provides a hook to get information about any (managed) exception getting thrown in the AppDomain. You can not handle the Exception this way! It is only a sort of notification


    Update: regarding your comment about a "swallowed exception" on another answer - and just a shot into the dark:
    On x64 systems exceptions that get thrown in a windows' onLoad method can not be caught in your Main() method.
    see this SO article for reference


    Update 2: As for Threads I think that you would have to implement it yourself. This would involve some sort of polling and would harm performance, but I guess for debugging it is OK in most cases. This could be done using

    var threads = Process.GetCurrentProcess().Threads;
    

提交回复
热议问题