Use ELMAH to log database errors

I am using ELMAH to handle exceptions in my ASP.Net MVC project. I would like to use it to register errors, such as database connection timeout, query connection timeout, and others. Is this possible with ELMAH?

+4
source share
2 answers

If you allow an exception to propagate to the Elmah web module, it will automatically register these exceptions.

However, you can program the log directly in Elmah, there are several ways to do this:

In catch code, you can use code like this in code:

try{....} catch(Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } 

Another way to do this:

 Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex)); 

I would, however, port this code to a more general IErrorLogger style interface so that your lower-level code does not need to be heavily dependent on Elmah itself

+5
source

I don’t know if this was with ELMAH (he never used it), but you can do it all with MS Ent Libs, which can be configured.

http://msdn.microsoft.com/en-us/library/cc467894.aspx

http://entlib.codeplex.com/wikipage?title=EntLib5%20Beta1

0
source

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


All Articles