2009-11-24 81 views
4

有沒有一種方法可以使用異常消息過濾elma中的異常?過濾elmah中的例外文本

示例:
「System.Web.HttpException:Request timed out。」我不想過濾掉所有的HttpException,但只是超時請求。
「System.Web.HttpException:超過最大請求長度。」

我不想做的是編寫自己的代碼。那麼有可能通過buildin-web.config配置來做到這一點?

謝謝!

回答

11

是的,你可以。只需使用正則表達式來詢問消息。有關如何比較異常消息的詳細信息,請參閱下面的示例。

<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> 
+1

interigate - >詢問。 ;) – 2013-10-02 09:42:22

+0

謝謝@IanGrainger。現在修復它。 – 2013-10-04 05:27:38

7

您可以設置在Global.asax的事件處理程序,以避免難看的配置正則表達式設置:

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

Error Filtering