I have an assembly containing a number of classes. This is a class library type assembly, not a windows forms application. It's also single threaded.
Is there a way to catch all un-handled exceptions so that I can log them?
In my opinion, putting such logic inside library is not a good idea. I think it should be application responsibility to decide how to deal with exceptions (both handled and unhandled). However you might look at AppDomain.UnhandledException. You can install such handler for CurrentDomain and do something there. However doing this way you are restricting usages of you library (for example implying that library would be used only in one domain). Also you will receive notifications for all unhandled exceptions even totally unrelated to your assembly.
I think that better idea is to allow developers that use your library to do their job dealing with all unhandled exceptions (possibly with UnhandledException installed by the application).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With