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 application and then view its logs?
Update: I'll clarify that a bit. I want standard .txt (or any custom) logs, the format doesn't matter. The main point is I want to log all exceptions that occurred in all third-party libraries without adding code to them.
You can use your own logging system or use third party lib called log4net.
If your thing is a web thing then you can use https://elmah.github.io/ to automatically log errors (without even stopping your service!)
I guess the feature you are searching for is called
FirstChanceException
and can be accessed via the AppDomain.FirstChanceException EventEssentially 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 notificationUpdate: 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 usingFor handled exceptions you'd most likely need to log them explicitly. Even if that's not the case semantically there's a huge difference to handled and unhandled exceptions.
Handled exceptions are no longer an exceptional situation. Some one writing the code said. I know how to handle this exception and proceed correctly afterwards.
For unhandled exceptions have a look at Elmah
Alternatively to Log4Net proposed by some guys, you could also use NLog. I don't know the differences between the two solutions, I just know that I'm happy with NLog.
You might go with aspects. If for example you take PostSharp, and write an aspect that creates a try-catch for every function, logging is done in the aspect. After logging just rethrow it.
Example code from their website to have a complete answer with demo code:
Edit:
You could use any logger like log4net, NLog or the enterprise library ( my preferred way of doing logging and some other stuff ). But that isn't really the task here. The task is - IMHO - to inject logging into the project with as less manual coding as possible.