Capturing all exceptions in the current topic

In my web application, I have one way async WCF. In this service, I want to catch all exceptions, as I do in global.asax Application_Error. I tried to handle these events:

AppDomain.CurrentDomain.UnhandledException += (s,e) => { //some logic }; AppDomain.CurrentDomain.FirstChanceException += (s,e) => { //some logic }; 

even tried:

 //this one is for Win Forms Application Application.ThreadException += (s,e) => { //some logic }; 

and

 //this one is for Web Application HttpContext.Current.ApplicationInstance.Error += (s,e) => { //some logic }; 

But not one of these handlers has been reached.

Any ideas what else I can try?

+4
source share
2 answers

If you put these lines of code on a web page, they will be lost. What for? Because the web page has a limited lifespan. To keep your event processing alive, you need to put it in the global asax file.

+2
source

WCF allows you to insert an object that implements IErrorHandler into dispatcher error handlers.

The MSDN page contains sample code.

+2
source

Source: https://habr.com/ru/post/1442315/


All Articles