1
#region Copyright & License
3
// Copyright 2001-2005 The Apache Software Foundation
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
9
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
25
namespace log4net.Filter
28
/// This is a simple filter based on <see cref="Level"/> matching.
32
/// The filter admits three options <see cref="LevelMin"/> and <see cref="LevelMax"/>
33
/// that determine the range of priorities that are matched, and
34
/// <see cref="AcceptOnMatch"/>. If there is a match between the range
35
/// of priorities and the <see cref="Level"/> of the <see cref="LoggingEvent"/>, then the
36
/// <see cref="Decide"/> method returns <see cref="FilterDecision.Accept"/> in case the <see cref="AcceptOnMatch"/>
37
/// option value is set to <c>true</c>, if it is <c>false</c>
38
/// then <see cref="FilterDecision.Deny"/> is returned. If there is no match, <see cref="FilterDecision.Deny"/> is returned.
41
/// <author>Nicko Cadell</author>
42
/// <author>Gert Driesen</author>
43
public class LevelRangeFilter : FilterSkeleton
45
#region Member Variables
48
/// Flag to indicate the behavior when matching a <see cref="Level"/>
50
private bool m_acceptOnMatch = true;
53
/// the minimum <see cref="Level"/> value to match
55
private Level m_levelMin;
58
/// the maximum <see cref="Level"/> value to match
60
private Level m_levelMax;
67
/// Default constructor
69
public LevelRangeFilter()
76
/// <see cref="FilterDecision.Accept"/> when matching <see cref="LevelMin"/> and <see cref="LevelMax"/>
80
/// The <see cref="AcceptOnMatch"/> property is a flag that determines
81
/// the behavior when a matching <see cref="Level"/> is found. If the
82
/// flag is set to true then the filter will <see cref="FilterDecision.Accept"/> the
83
/// logging event, otherwise it will <see cref="FilterDecision.Neutral"/> the event.
86
/// The default is <c>true</c> i.e. to <see cref="FilterDecision.Accept"/> the event.
89
public bool AcceptOnMatch
91
get { return m_acceptOnMatch; }
92
set { m_acceptOnMatch = value; }
96
/// Set the minimum matched <see cref="Level"/>
100
/// The minimum level that this filter will attempt to match against the
101
/// <see cref="LoggingEvent"/> level. If a match is found then
102
/// the result depends on the value of <see cref="AcceptOnMatch"/>.
105
public Level LevelMin
107
get { return m_levelMin; }
108
set { m_levelMin = value; }
112
/// Sets the maximum matched <see cref="Level"/>
116
/// The maximum level that this filter will attempt to match against the
117
/// <see cref="LoggingEvent"/> level. If a match is found then
118
/// the result depends on the value of <see cref="AcceptOnMatch"/>.
121
public Level LevelMax
123
get { return m_levelMax; }
124
set { m_levelMax = value; }
127
#region Override implementation of FilterSkeleton
130
/// Check if the event should be logged.
132
/// <param name="loggingEvent">the logging event to check</param>
133
/// <returns>see remarks</returns>
136
/// If the <see cref="Level"/> of the logging event is outside the range
137
/// matched by this filter then <see cref="FilterDecision.Deny"/>
138
/// is returned. If the <see cref="Level"/> is matched then the value of
139
/// <see cref="AcceptOnMatch"/> is checked. If it is true then
140
/// <see cref="FilterDecision.Accept"/> is returned, otherwise
141
/// <see cref="FilterDecision.Neutral"/> is returned.
144
override public FilterDecision Decide(LoggingEvent loggingEvent)
146
if (loggingEvent == null)
148
throw new ArgumentNullException("loggingEvent");
151
if (m_levelMin != null)
153
if (loggingEvent.Level < m_levelMin)
155
// level of event is less than minimum
156
return FilterDecision.Deny;
160
if (m_levelMax != null)
162
if (loggingEvent.Level > m_levelMax)
164
// level of event is greater than maximum
165
return FilterDecision.Deny;
171
// this filter set up to bypass later filters and always return
172
// accept if level in range
173
return FilterDecision.Accept;
177
// event is ok for this filter; allow later filters to have a look..
178
return FilterDecision.Neutral;