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..
It doesn't help you learn how to configure ELMAH, but the easiest way to prevent a 404 for requests for a favicon is to provide one...
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.
i just ignore the route rather than configuring Elmah. This works for me:
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});