0

Everytime Elmah logs an error the error is logged twice. 100% identical with exact the same Timestamp. I have no special configuration in the web.config. I have created a ElmahHandleErrorAttribute an added two filters:

filters.Add(new ElmahHandleErrorAttribute {

            ExceptionType = typeof(System.Data.Common.DbException),
            // DbError.cshtml is a view in the Shared folder.
            View = "DbError",
            Order = 2
        });

filters.Add(new ElmahHandleErrorAttribute {

            ExceptionType = typeof(Exception),
            // DbError.cshtml is a view in the Shared folder.
            View = "Error",
            Order = 3
        });

Some Snippets from web.config:

<httpModules>
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>

and

<modules runAllManagedModulesForAllRequests="true">
        <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>

In the ElmaHandleErrorAttribute this code:

public override void OnException(ExceptionContext context) {
        base.OnException(context);
        if (!context.ExceptionHandled       
            || TryRaiseErrorSignal(context) 
            || IsFiltered(context))         
            return;

        LogException(context);
    }

I have searched a lot, but no solution fits to my problem. No double entries in web.config or something like this.

It's no big problem, but it's annoying.

thx in advance

©a-x-i

a-x-i
  • 303
  • 5
  • 13
  • 1
    You are not checking the ExceptionType in your custom ElmaHandleErrorAttribute. So it will be called 2 times. Because DbException is inherited from the Exception. – VahidN Dec 11 '12 at 09:27
  • Please see my suggested answer to this similar question http://stackoverflow.com/a/16794746/589827 – DGreen May 28 '13 at 14:36

1 Answers1

-1

I had the same problem with my setup, so I made a ExceptionLogger class. Then added a static field to it to keep a list of the exceptions it logged. Then when the onException event hapens it checks for the last exception logged to avoid logging duplicates.

public class ExceptionLogger
{
    public static List<Exception> loggedExceptions = new List<Exception>();

    public static void LogException(Exception e) {

...

    public override void OnException(ExceptionContext context)
    {
        base.OnException(context);
        var e = context.Exception;

        if (!e.Equals(ExceptionLogger.loggedExceptions.Last()))
        {
            ExceptionLogger.LogException(e);
        }

     }
gmlacrosse
  • 362
  • 2
  • 8