How to properly declarative filter in Web.Config

167 views
Skip to first unread message

Eeyore145

unread,
Oct 16, 2009, 3:54:54 PM10/16/09
to ELMAH
Hello all:

I have my regular expressions and conditions correct, I've tested them
but I believe I might be doing this wrong. I understand that in the
web.config file I can set up error filter under the <test> node:

<errorFilter>
<test>

But I have three seperate conditions I want to filter for. I believe
I have done this wrong by building a structure like so:

<errorFilter>
<test>
<and>
.........
<or>
..............
</or>
</and>
</test>

<test>
<is-type-compatible binding="xxxxx"/>
</test>

<test>
<and>
..............
</and>
</test>

</errorFilter>

As you can see I have set up 3 seperate <test> nodes for each stand
alone condition. I have three which should be evaluated as seperate
entities

1) And OR
2) simple if type compatible
3) And condition

Today one of the errors I have set up (the bottom test) to filter was
still thrown, so now I am assuming, ELMAH will only look at the FIRST
test tag, is that correct? Or can I have multiple test nodes and is
this the proper way to do it?

If not, how do I declare within one Test node three seperate
conditions to check, one as an AND/OR, one just a check of type
compatible and another and condition.

Thanks

Atif Aziz

unread,
Oct 18, 2009, 8:41:13 PM10/18/09
to el...@googlegroups.com
There can only be one <test> node under <errorFilter> so if you have several then only the first one will be considered. If you want multilpe, independent test conditions, then you simply put them within an <or> under <test>, like this:
 
<errorFilter>
  <test>
    <or>
      <and>
        ...
        <or>
          ...
        </or>
      </and>
      <is-type-compatible binding="xxxxx"/>     
      <and>
        ...
      </and>
    </or>
  </test>
</errorFilter>

As you can see, it's just arbitrary nesting where you just OR the outermost conditions.
 
- Atif

Eeyore145

unread,
Oct 21, 2009, 11:06:41 AM10/21/09
to ELMAH
That makes sense and it works as expected. Sorry if I missed that in
the documentation :), I wasn't sure if the test node was literally
"per test" or it just encapsulated all of them.

thanks again
> > Thanks- Hide quoted text -
>
> - Show quoted text -

Atif Aziz

unread,
May 18, 2010, 2:15:03 PM5/18/10
to Dasha Fefelova, el...@googlegroups.com
Tell me if I've understood you right. You don't want an error notification by e-mail for 404s or where the error message is exactly the string “Padding is invalid and cannot be removed.” In all other cases, you want an error notification by e-mail but you're not getting any?
 
- Atif
On Mon, May 17, 2010 at 1:54 PM, Dasha Fefelova <dasha.f...@gmail.com> wrote:
Hello Atif.

I'm now struggling with similar problem. In my case, when I added <or>
node, I now get no e-mails with notifications at all. What could be
causing this situation? Below you can find an extract from my
web.config. As a result I'm getting no e-mails at all for some reason.

<errorFilter>
     <test>
       <or>
                       <and>
                               <equal binding="HttpStatusCode" value="404" type="Int32" />
                               <regex binding="FilterSourceType.Name" pattern="mail" />
                       </and>
                       <and>
                               <equal binding="Exception.Message" value="Padding is invalid and
cannot be removed." type="String" />
                               <regex binding="FilterSourceType.Name" pattern="mail" />
                       </and>
               </or>
     </test>
   </errorFilter>

--
You received this message because you are subscribed to the Google Groups "ELMAH" group.
To post to this group, send email to el...@googlegroups.com.
To unsubscribe from this group, send email to elmah+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/elmah?hl=en.

Atif Aziz

unread,
May 18, 2010, 2:16:54 PM5/18/10
to Dasha Fefelova, el...@googlegroups.com

I quickly gave your filter test a spin and it should be working fine. Below are the results of my interactive tests in IronPython 2.6.1 on .NET 4.0 using ELMAH 1.1:
 
IronPython 2.6.1 (2.6.10920.0) on .NET 4.0.30319.1
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>>
>>> clr.AddReference('Elmah')
>>> from Elmah.Assertions import AssertionFactory
>>> from Elmah import ErrorMailModule, ErrorLogModule
>>> from Elmah.ErrorFilterModule import AssertionHelperContext
>>>
>>> clr.AddReference('System.Web')
>>> from System.Web import HttpException
>>>
>>> clr.AddReference('System.Xml')
>>> from System.Xml import XmlDocument
>>>
>>> xml = """
...     <or>

...         <and>
...             <equal binding="HttpStatusCode"
...                    value="404" type="Int32" />
...             <regex binding="FilterSourceType.Name"
...                    pattern="mail" />
...         </and>
...         <and>
...             <equal binding="Exception.Message"
...                    value="Padding is invalid and cannot be removed."
...                    type="String" />
...             <regex binding="FilterSourceType.Name"
...                    pattern="mail" />
...         </and>
...     </or>

...     """
>>>
>>> config = XmlDocument()
>>> config.LoadXml(xml)
>>>
>>> assertion = AssertionFactory.Create(config.DocumentElement)
>>>
>>> mailmod = ErrorMailModule()
>>> logmod = ErrorLogModule()
>>>
>>> error = HttpException(404, None)
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
True
>>>
>>> error = HttpException(500, None)
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
False
>>>
>>> error = HttpException('Padding is invalid and cannot be removed.')
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
True
>>>
>>> context = AssertionHelperContext(logmod, error, None)
>>> print assertion.Test(context)
False
>>>
 
If the above appears distorted due to line-wrapping, I've also posted a version at:
http://gist.github.com/405314
 
Where you see True, the error should not get mailed, which is I think what you want.

Reply all
Reply to author
Forward
0 new messages