I have been investigating the best way to handle all the exceptions of an application without messing much with the code. The main objective here is to send information about the exceptions to an external platform such as Application Insights. So far I've found the following methods:
Castle Interceptor:
This is the best approach so far, the thing is that, for the methods to be intercepted either the methods are virtual, or the class must be interfaced. Since I'm working on a really big application these changes are not desired.Events:
Using AppDomain UnhandledException is also to be considered, but since I have several app domains that would require a lot of changes a messing with classes only for the exceptions, which is not optimal since classes should not be messed just because of exception handling. Besides the number of AppDomains I also have several threads running from which exceptions are not caught by this kind of handlers.PostSharp:
PostSharp works similarly to Castle, and the problem here if I understood correctly, is that I would have to add attributes/decorators to all the methods I want intercepted, also not a very good approach.
If anyone has any suggestions on the best approach here I would be very appreciated.