Question

Is there a way to filter exceptions in elma using the exception message?

Examples:
"System.Web.HttpException: Request timed out." I don't want to filter out all HttpException, but only the timed-out requests.
"System.Web.HttpException: Maximum request length exceeded."

What I don't want to do is write own code for that. So is it possible to do this with the buildin-web.config configuration?

Thank you!

Was it helpful?

Solution

Yes you can. Just use a regular expression to interrogate the message. See the example below for details on how to compare the exception message.

<errorFilter>
  <test>
    <!-- http://groups.google.com/group/elmah/t/cbe82cee76cc6321 -->
    <and>
      <is-type binding='Exception'
               type='System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' />
      <regex binding='Exception.Message'
             pattern='invalid\s+viewstate'
             caseSensitive='false' />
      <regex binding='Context.Request.UserAgent'
             pattern='Trident/4(\.[0-9])*'
             caseSensitive='false' />
    </and>
  </test>
</errorFilter>

OTHER TIPS

You can set up an event handler in your global.asax to avoid ugly configuration regex settings:

void ErrorMail_Filtering(object sender, Elmah.ExceptionFilterEventArgs e) 
{     
    if (e.Exception.Message.Contains("Request timed out"))
        e.Dismiss(); 
}

See Error Filtering.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top