Filter on exception text in elmah

前端 未结 2 364
青春惊慌失措
青春惊慌失措 2021-01-01 04:00

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 a

相关标签:
2条回答
  • 2021-01-01 04:09

    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>
    
    0 讨论(0)
  • 2021-01-01 04:26

    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.

    0 讨论(0)
提交回复
热议问题