views:

219

answers:

2

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

A: 

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);
}
codeulike
+1  A: 

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.

Todd Smith