Reputation: 32768
I've configured ELMAH in my ASP.NET MVC 4 application. I've written some code in the Application_Error
event to check the status code of the error and invoke an error controller to return appropriate view for 404, 500 errors.
Elmah logs the error if it reaches Application_Error
. Instead of allowing ELMAH autmatically doing that I want to do trigger it manually from the Application_Error
. So, is there any configuration property i can set in web.config to disable elmah automatically logging the errors.
Upvotes: 3
Views: 868
Reputation: 4388
You can do something like this:
Global.asax.cs:
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (ConfigurationManager.AppSettings["LoggingEnabled"] == "0")
{
e.Dismiss();
return;
}
var httpContext = e.Context as HttpContext;
if (httpContext == null)
{
return;
}
var error = new Error(e.Exception, httpContext);
ErrorLog.GetDefault(httpContext).Log(error);
e.Dismiss();
}
web.config:
<appSettings>
<add key="LoggingEnabled" value="1"/>
</appSettings>
Upvotes: 1