NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
862 stars 170 forks source link

Handling expected and bogus errors #54

Closed stijnherreman closed 9 years ago

stijnherreman commented 9 years ago

We have a number of expected and bogus errors:

These can usually be identified based on IP address, URL or request headers. I don't want to outright ignore these errors, but it would be useful to set up persistent filters for this, for example in the form of a tab in the log.

Any ideas or suggestions for how this could be implemented? Or should I just give it a go, see what I can come up with and make a PR?

cocowalla commented 9 years ago

I've got the same issue, but with McAfee Vulnerability Manager. Did you find a way to exclude client IP addresses?

CptRobby commented 9 years ago

You could attach an event handler to the static ErrorStore.OnBeforeLog event (which is defined in ErrorStore.Extensibility.cs). The ErrorBeforeLogEventArgs object that is passed in contains the Error object and an Abort boolean. If Abort is set to true in your event handler, it will prevent the error from being logged. Thus you could do something like the following:

public void ErrorStore_OnBeforeLog(object sender, ErrorBeforeLogEventArgs args)
{
    if (args.Error.IPAddress == "127.0.0.1") //Just an example
    {
        args.Abort = true;
    }
}

There are also other ways of excluding specific errors, but this provides you with the most control. Enjoy! ;)

cocowalla commented 9 years ago

Perfect, thanks :)