elmah-mvc icon indicating copy to clipboard operation
elmah-mvc copied to clipboard

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

Open RehanSaeed opened this issue 9 years ago • 0 comments

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 }
        );
    }
}

RehanSaeed avatar Apr 13 '15 11:04 RehanSaeed