多种ELMAH过滤条件 [英] Multiple ELMAH Filter Conditions

查看:111
本文介绍了多种ELMAH过滤条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以通过以下逻辑编写ELMAH来过滤错误日志记录:

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

如果错误是favicon.ico OR 上的404,则错误是/1.xml OR 上的404,则错误是/2.xml

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

我找到了在favicon.ico上执行此操作的方法,如下所示:

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>

但是由于某些原因,我不明白如何在OR条件下执行此操作.任何帮助将不胜感激.

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

推荐答案

以下方法可以解决问题,否则您可以入门:

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>

基本上,这将过滤HTTP状态代码为404 且分组在or元素下的正则表达式模式之一与请求URL匹配的错误.

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.

这篇关于多种ELMAH过滤条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆