alexbeletsky / elmah-mvc

Painless integration of ELMAH into ASP.NET MVC application
http://nuget.org/packages/Elmah.MVC
Apache License 2.0
266 stars 61 forks source link

Elmah not logging 404 Not Found errors when using MVC Attribute Routing #60

Open RehanSaeed opened 9 years ago

RehanSaeed commented 9 years ago

All errors seem to be logged in Elmah except 404 Not Found errors. I have now narrowed this error down to a routing problem. I am using attribute routing only and do not have any calls to System.Web.MvcRouteCollectionExtensions.MapRoute anywhere in my routing configuration. As soon as I add the default MapRoute code back in, 404 Not Found errors are logged once more.

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("Content/{*pathInfo}");
        routes.IgnoreRoute("Scripts/{*pathInfo}");
        routes.IgnoreRoute("elmah");

        routes.MapMvcAttributeRoutes();

        // Removing the line below stops Elmah from logging 404 Not Found errors.
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}