Multiple ELMAH Filter Conditions

百般思念 提交于 2019-12-11 03:29:41

问题


I wanted to know if there is a way that I can write ELMAH to filter out error logging under the following logic:

If the error is a 404 on favicon.ico OR the error is 404 on /1.xml OR the error is 404 on /2.xml

I have found the way to just do it on the favicon.ico as shown:

 <errorFilter>
  <test>
    <and>
      <equal binding="HttpStatusCode" value="404" type="Int32" />
      <regex binding="Context.Request.ServerVariables['URL']" pattern="/favicon\.ico(\z|\?)" />
    </and>
  </test>
</errorFilter>

But for some reason, I cannot understand how to do it for the OR conditions. Any help will be much appreciated.


回答1:


The following should do the trick or otherwise get you started:

<errorFilter>
  <test>
    <and>
      <equal binding="HttpStatusCode" value="404" type="Int32" />
      <or>
        <regex binding="Context.Request.ServerVariables['URL']" 
               pattern="/favicon\.ico(\z|\?)" />
        <regex binding="Context.Request.ServerVariables['URL']" 
               pattern="/[1-2]\.xml(\z|\?)" />
      </or>
    </and>
  </test>
</errorFilter>

Basically, this will filter errors where the HTTP status code is 404 and one of the regular expressions patterns grouped under the or element match the request URL.



来源:https://stackoverflow.com/questions/5470214/multiple-elmah-filter-conditions

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