Debug/Trace messages using ELMAH in MVC application

一曲冷凌霜 提交于 2019-12-10 04:51:42

问题


How do we add debug/Trace messages using ELMAH in MVC application


回答1:


ELMAH is usually used to report exceptions and not as a general Debug/Trace log.

For Debug/Trace logging I would suggest a combination of log4net and Log4PostSharp.




回答2:


Elmah will catch unhandled exceptions automatically.

By tracing I think you mean logging exceptions that are handled?

If you want to manually log handled exceptions, the process in MVC is the same as for ASP.NET:

Add a reference to the Elmah DLL to your project, and then use Elmah.ErrorSignal.FromCurrentContext().Raise(), like this:

try
{
    throw new ApplicationException("raised for elmah to catch");
}
catch (System.ApplicationException ae)
{
    Elmah.ErrorSignal.FromCurrentContext().Raise(ae);
}


来源:https://stackoverflow.com/questions/1377997/debug-trace-messages-using-elmah-in-mvc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!