How do we add debug/Trace messages using ELMAH in MVC application
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);
}
来源:https://stackoverflow.com/questions/1377997/debug-trace-messages-using-elmah-in-mvc-application