Background Exception Exception with Elmah

I have an MVC + SignalR application that has many Reactive Extensions subscribers, all of which are projections of data coming from Socket in real time. Some of these subscriptions do not work as expected, and when they throw an exception, it just goes empty if I am not debugging.

I was hoping that I could use Elmah to automatically log these unhandled exceptions, but it seems that if the exception does not occur on the same thread processing the request / response, for example, it causes a yellow death screen, Elma does not touch it. Therefore, my question is twofold:

  • Can I get Elmah to automatically log exceptions in background / worker processes?

  • If the answer to # 1 is β€œno,” what is my best option, except that I wrap my subscriptions in try / catch blocks at a very high level?

+5
source share
1 answer

Announcement 1) If this does not happen, probably it is not.

I don’t know how exactly you use background threads, but I will try to explain if ELMAH processing works. ELMAH is integrated into the ASP.NET pipeline, and when an error occurs, it is processed by the ASP.NET pipeline, which displays the error page (for example, http error 500) and calls ErrorLogModule . Also, citing the Use of HTTP modules and handlers to create ASP.NET plug-ins β†’ Adding ELMAH to an ASP.NET Web Application

The section adds the ErrorLogModule HTTP module to the ASP.NET HTTP pipeline. Make sure you enable this one, otherwise ELMAH will not listen for the Error event and therefore no unhandled exceptions will be logged.

Announcement 2) . Since you are using Reactive Extensions, you can handle onError in which you can automatically enter Elmah. If you do not want to write errors everywhere in OnError mode, just create your own function or method extension that will automatically wrap you. Writing in ELMAH manually is easy to call:

 Elmah.ErrorSignal.FromCurrentContext().Raise(ex); 
+1
source

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


All Articles