I am learning the best way to handle all the exceptions of the application without much abuse of the code. The main goal here is to send exception information to an external platform such as Application Insights. So far, I have found the following methods:
Castle Interceptor:
This is the best approach so far, the fact is that in order for the methods to be intercepted, either the methods are virtual, or the class must be conjugated. Since I'm working on a really big application, these changes are undesirable.
Developments:
Using AppDomain UnhandledException should also be considered, but since I have several application domains that will need a lot of changes, they will randomly get confused with classes for exceptions only, which is not optimal since classes should not be mixed just because of exception handling. Besides the number of AppDomains, I also have several threads from which exceptions are not caught by such handlers.
PostSharp:
PostSharp works similarly to Castle, and the problem here, if I understood correctly, is that I will have to add attributes / decorators to all the methods that I want to intercept, as well as a not-so-good approach.
If anyone has suggestions for a better approach, I will be very grateful.
source share