Table of Contents

Class StringMatchFilter

Namespace
log4net.Filter
Assembly
log4net.dll

Simple filter to match a string in the rendered message

public class StringMatchFilter : FilterSkeleton, IFilter, IOptionHandler
Inheritance
StringMatchFilter
Implements
Derived
Inherited Members

Remarks

Simple filter to match a string in the rendered message

Constructors

StringMatchFilter()

Default constructor

public StringMatchFilter()

Fields

m_acceptOnMatch

Flag to indicate the behavior when we have a match

protected bool m_acceptOnMatch

Field Value

bool

m_regexToMatch

A regex object to match (generated from m_stringRegexToMatch)

protected Regex m_regexToMatch

Field Value

Regex

m_stringRegexToMatch

A string regex to match

protected string m_stringRegexToMatch

Field Value

string

m_stringToMatch

The string to substring match against the message

protected string m_stringToMatch

Field Value

string

Properties

AcceptOnMatch

public bool AcceptOnMatch { get; set; }

Property Value

bool

Remarks

The AcceptOnMatch property is a flag that determines the behavior when a matching Level is found. If the flag is set to true then the filter will Accept the logging event, otherwise it will Neutral the event.

The default is true i.e. to Accept the event.

RegexToMatch

Sets the regular expression to match

public string RegexToMatch { get; set; }

Property Value

string

Remarks

The regular expression pattern that will be matched against the rendered message. If the message matches this pattern then the filter will match. If a match is found then the result depends on the value of AcceptOnMatch.

One of StringToMatch or RegexToMatch must be specified.

StringToMatch

Sets the static string to match

public string StringToMatch { get; set; }

Property Value

string

Remarks

The string that will be substring matched against the rendered message. If the message contains this string then the filter will match. If a match is found then the result depends on the value of AcceptOnMatch.

One of StringToMatch or RegexToMatch must be specified.

Methods

ActivateOptions()

Initialize and precompile the Regex if required

public override void ActivateOptions()

Remarks

This is part of the IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined state and must not be used.

If any of the configuration properties are modified then ActivateOptions() must be called again.

Decide(LoggingEvent)

Check if this filter should allow the event to be logged

public override FilterDecision Decide(LoggingEvent loggingEvent)

Parameters

loggingEvent LoggingEvent

the event being logged

Returns

FilterDecision

see remarks

Remarks

The rendered message is matched against the StringToMatch. If the StringToMatch occurs as a substring within the message 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.