开发者

Use ELMAH to log database errors

开发者 https://www.devze.com 2022-12-22 03:47 出处:网络
I\'m using ELMAH to handle the exceptions in my ASP.Net MVC project开发者_JS百科. I would like to use it to log errors like database connection timeout, query connection timeout and others. Is this po

I'm using ELMAH to handle the exceptions in my ASP.Net MVC project开发者_JS百科. I would like to use it to log errors like database connection timeout, query connection timeout and others. Is this possible with ELMAH?


If you let the exception propogate out to the Elmah Web Module it will automatically log these exceptions.

You can however programatically log directly to Elmah, there are a couple of ways to do this:

You can use code like this in your catch clause in code:

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

Another way of doing this is this:

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

I would however wrap this code into a more generic IErrorLogger style interface so that your lower level code doesn't need to have a hard dependency on Elmah itself


I don't know if it is with ELMAH (never used it) but you can do all that with the MS Ent Libs, which are highly configurable.

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消