Ben Biddington

Whatever it is, it's not about "coding"

Posts Tagged ‘configuration

Log pollution and log4net

leave a comment »

LevelRangeFilter

Small tip for configuring filters — take care with acceptOnMatch, read the documentation for the exact behaviour.

For example, to get a LevelRangeFilter to pass the event on the subsequent filters, use the following:

<filter type="log4net.Filter.LevelRangeFilter">
    <acceptOnMatch value="false" />
    <levelMin value="DEBUG" />
    <levelMax value="FATAL" />
</filter>
<filter type="log4net.Filter.LoggerMatchFilter">
    <loggerToMatch value="xxx-yyy-zzz"/>
</filter>
<filter type="log4net.Filter.DenyAllFilter" />

The default value for acceptOnMatch is true, so had we left it out we would be logging everything between DEBUG and FATAL.

FilterSkeleton.Decide

This is the operation that determines whether the filter should deny, accept or pass on a log event:.

[LoggerMatchFilter.Decide] The rendered message is matched against the LoggerToMatch. If the LoggerToMatch equals the beginning of the incoming LoggerName (StartsWith) then a match will have occurred. If no match occurs this function will return Neutral allowing other filters to check the event. If a match occurs then the value of AcceptOnMatch is checked. If it is true then Accept is returned otherwise Deny is returned.

[LevelMatchFilter.Decide] If the Level of the event matches the level of the filter then the result of the function depends on the value of AcceptOnMatch. If it is true then the function will return Accept, it it is false then it will return Deny. If the Level does not match then the result will be Neutral.

The value of acceptOnMatch can be important if you don’t want your filter to exit early. In this example, we have to set it to false on our LevelRangeFilter for this reason. Perhaps we would be better to reorder them.

References

Advertisements

Written by benbiddington

25 March, 2009 at 17:30