Debug/Trace messages using ELMAH in MVC application

主宰稳场 提交于 2019-12-05 08:59:53
Todd Smith

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.

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