Reputation: 2005
I can't get ELMAH to log errors to my AppData
folder for any exceptions except for 404
errors. I'm not sure what the problem could be. I'm guessing it's because I have <customErrors mode="RemoteOnly" defaultRedirect="~/Views/Shared/Error.cshtml">
, but I've tried doing what's recorded HERE and haven't had any luck. Here's my web.config (at least anything critical to using ELMAH):
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<appSettings>
<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="true" />
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
<add key="elmah.mvc.allowedRoles" value="Programmers" />
<add key="elmah.mvc.allowedUsers" value="*" />
<add key="elmah.mvc.route" value="elmah" />
</appSettings>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<modules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data"/>
</elmah>
Here's my FilterConfig.cs
:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorLoggerFilter());
filters.Add(new HandleErrorAttribute());
}
}
And my Custom Elmah Handler:
public class ElmahHandleErrorLoggerFilter : System.Web.Mvc.IExceptionFilter
{
public void OnException(ExceptionContext context)
{
//Log only handled exceptions, because all others will be caught by ELMAH
if (context.ExceptionHandled)
{
ErrorSignal.FromCurrentContext().Raise(context.Exception);
}
}
}
Any thoughts on what I could be doing wrong or what I'm missing?
Upvotes: 3
Views: 2613
Reputation: 3277
Basically ELMAH will log all unhandled exceptions by default, also it will log all requests as well.
You even don't need any Log Filters.
All that you need is just to add runAllManagedModulesForAllRequests="true"
to ELMAH modules
section:
<modules runAllManagedModulesForAllRequests="true">
That will allows ELMAH to process all requests and log all errors.
Upvotes: 1