3

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?

Community
  • 1
  • 1
The Vanilla Thrilla
  • 1,915
  • 10
  • 30
  • 49
  • How does this behave if you remove the `ElmahHandleErrorLoggerFilter`? – Vasily Sliounaiev Apr 18 '14 at 16:21
  • It still does the same thing. Nothing is being logged. – The Vanilla Thrilla Apr 18 '14 at 16:33
  • Try adding `` [Also have a look at this answer.](http://stackoverflow.com/a/933586/1644019) – Vasily Sliounaiev Apr 18 '14 at 17:27
  • What kind of exception is throw and where? By the way: 1. you don't need the `ElmahHandleErrorLoggerFilter` and `HandleErrorAttribute` since `Elmah.MVC` injects one if `disableHandleErrorFilter` is `false`. 2. `Error.cshtml` is not accessible from browsers (try accessing /Views/Shared/Error.cshtml from your browser and see what happens). You must use an HTML file outside the views folder. – LostInComputer Apr 18 '14 at 18:15

1 Answers1

1

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.

Dmitry Zaets
  • 3,289
  • 1
  • 20
  • 33