I can't get my Elmah email filters to work

♀尐吖头ヾ 提交于 2020-01-15 05:21:46

问题


I have a query about the following web.config setup and Elmah. The problem is that it I still get emails regarding the public action method issues when I don't want to. The filters I have in place don't seem to be working.

I am not entirely sure how the ANDs and ORs are supposed to work in Elmah email filtering, especially as this code is snipped from some project work I have taken onboard from other developers.

The tags are meant to prevent any errors from being reported via email that contain any of the words Index, cache or Login.

Can anyone help?

<configuration>
    <configSections>
        <!--Elmah sectionGroup-->
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        </sectionGroup>
  </configSections>  

 <elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
<errorMail from="" to="" subject="Error(Elmah)" async="true " />
    <security allowRemoteAccess="1"/>
<errorFilter>
  <test>
    <or>
        <is-type binding="BaseException" type="System.InvalidOperationException" />
</or>
<or>
    <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" />
</or>
<or>
    <regex binding="Exception.Message" pattern="(?ix: \b public action method     'Index' was not found on controller \b )" />
    <regex binding="Exception.Message" pattern="(?ix: \b public action method 'cache' was not found on controller \b )" />
    <regex binding="Exception.Message" pattern="(?ix: \b public action method 'Login' was not found on controller \b )" />
</or>
  </test>
</errorFilter>
  </elmah>  
  <location path="elmah.axd">
  </location>  
  <system.web>
  </system.web>
 <system.webServer>    
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</modules>
<handlers>
  <add name="httpHandler" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
   </handlers>
  </system.webServer>
</configuration>

回答1:


The test element can only have one child assertion so having multiple or elements underneath it means all but the first are being ignored. From your description, it seems your test element should instead read like this:

<test>
  <or> 
    <is-type binding="BaseException" type="System.InvalidOperationException" /> 
    <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" /> 
    <and> 
      <regex binding="FilterSourceType.Name" pattern="mail" />
      <regex binding="Exception.Message" pattern="(?ix: \b public \s action \s method \s '(Index|cache|Login)' \s was \s not \s found \s on \s controller \b )" /> 
    </and>
  </or> 
</test>

Note that I also went ahead and folded the three regex elements into one and fixed the pattern to delimit words correctly (\b on edges and \s inbetween).



来源:https://stackoverflow.com/questions/10799538/i-cant-get-my-elmah-email-filters-to-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!