Why am I getting duplicate exception records using ELMAH in ASP.NET MVC?

I am new to ELMAH, but now I am working with MVC. After reading several blogs on this topic, I pursue a path ErrorControllerthat processes 404 pages and unknown errors, and makes a default route that forwards all unknown paths to 404 on this controller.

The problem is that ELMAH logs each error twice ; detailed logs are completely identical, with the exception of their identification number indicated in parentheses in the title.

Anyone else come across this? Routing seems to work just fine, except that you need to port the default route {controller}/{action}/{id}.

Here is 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 the routing code:

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

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

EDIT: ErrorController, :

/// <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();
    }
}
+3
1

?
, ErrorDefault catchAll, . , catchAll , .

- :

// All other pages use the default route.
routes.MapRoute("Default", "{controller}/{action}/{id}",
    new { controller = "Applications", action = "Index", id = "" }
);

// Show a 404 error page for anything else.
routes.MapRoute("Error", "{*url}",
    new { controller = "Error", action = "notfound" }
);

?

0

Source: https://habr.com/ru/post/1734433/


All Articles