I noticed out of the box that ELMAH logs a 404 not found for favico on my local server. How do I suppress this error through a filter? I'm not so familiar with configurating it yet..
The official elmah Error Filtering page explains a number of ways this 404 favicon error could be supressed.
You could filter out all 404 errors declaratively in the web.config like so. I'm not certain there is a way to only surpress a 404 for a favicon though.
<errorFilter>
<test>
<equal binding="HttpStatusCode" value="404" type="Int32" />
</test>
</errorFilter>
If you wanted to do it programmatically, you could dismiss the error in the ErrorLog or ErrorEmail filtering events as explained in the official docs. The below code is a bit overkill, but it demonstrates how you could filter out only 404 errors for a /favicon.ico request.
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (((HttpException)e.Exception.GetBaseException()).GetHttpCode() == 404
&& ((HttpContext)e.Context).Request.Path == "/favicon.ico")
{
e.Dismiss();
}
}
I'd personally prefer to either filter all 404s declaratively through the web.config, or just provide a favicon like Joel suggests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With