views:

57

answers:

0

I'm brand new to ELMAH but I've been working with MVC for a little while now. After reading several blogs on the subject I'm pursuing the road of having an ErrorController that handles 404 and unknown-error pages, and making a default route that forwards all unknown paths to the 404 action on that controller.

The problem is that ELMAH logs every error twice; the detail logs are completely identical except for their identification number specified in brackets in the title.

Has anyone else run into this? The routing seems to work great apart from having to ditch default {controller}/{action}/{id} route.

Here's my configuration:

    <configSections>
      ...
            <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>
            ...
   </configSections>
   <system.web>
        ...
        <customErrors mode="On" defaultRedirect="~/error/unknown/">
                <error statusCode="404" redirect="~/error/notfound/"/>
        </customErrors>
        ...
        <httpHandlers>
        ...
             <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
        ...
 </httpHandlers>
        ...
        <httpModules>
     ...
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        </httpModules>
     </system.web>
     <system.webserver>
          <modules runAllManagedModulesForAllRequests="true">
               ...
               <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
          </modules>
          <handlers>
               ...
               <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
          </handlers>
     </system.webserver>
     <elmah>
         <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/errorlogpath" />
     </elmah>

And routing code:

    routes.MapRoute(
        "ErrorDefault",
        "error/{action}",
        new { controller = "error", action = "unknown", id = "" }
        );

    routes.MapRoute(
        "Default",
        "{*url}",
        new { controller = "error", action = "notfound", id = "" }
        );

EDIT: Here's the ErrorController as well, just for my testing purposes:

/// <summary>
/// Handles error page routing
/// </summary>
public class ErrorController : Controller
{
    /// <summary>
    /// Action for unknown errors
    /// </summary>
    /// <returns></returns>
    [AcceptVerbs(HttpVerbs.Get)]
    public ViewResult Unknown()
    {
        Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        return View();
    }

    /// <summary>
    /// Action for 404s
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    [AcceptVerbs(HttpVerbs.Get)]
    public ViewResult NotFound(string path)
    {
        Response.StatusCode = (int)HttpStatusCode.NotFound;
        return View();
    }
}