~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Filter/.svn/text-base/LevelRangeFilter.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2001-2005 The Apache Software Foundation
4
 
//
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
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
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.
16
 
//
17
 
#endregion
18
 
 
19
 
using System;
20
 
 
21
 
using log4net;
22
 
using log4net.Core;
23
 
using log4net.Util;
24
 
 
25
 
namespace log4net.Filter
26
 
{
27
 
        /// <summary>
28
 
        /// This is a simple filter based on <see cref="Level"/> matching.
29
 
        /// </summary>
30
 
        /// <remarks>
31
 
        /// <para>
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.
39
 
        /// </para>
40
 
        /// </remarks>
41
 
        /// <author>Nicko Cadell</author>
42
 
        /// <author>Gert Driesen</author>
43
 
        public class LevelRangeFilter : FilterSkeleton
44
 
        {
45
 
                #region Member Variables
46
 
 
47
 
                /// <summary>
48
 
                /// Flag to indicate the behavior when matching a <see cref="Level"/>
49
 
                /// </summary>
50
 
                private bool m_acceptOnMatch = true;
51
 
 
52
 
                /// <summary>
53
 
                /// the minimum <see cref="Level"/> value to match
54
 
                /// </summary>
55
 
                private Level m_levelMin;
56
 
 
57
 
                /// <summary>
58
 
                /// the maximum <see cref="Level"/> value to match
59
 
                /// </summary>
60
 
                private Level m_levelMax;
61
 
 
62
 
                #endregion
63
 
 
64
 
                #region Constructors
65
 
 
66
 
                /// <summary>
67
 
                /// Default constructor
68
 
                /// </summary>
69
 
                public LevelRangeFilter()
70
 
                {
71
 
                }
72
 
 
73
 
                #endregion
74
 
 
75
 
                /// <summary>
76
 
                /// <see cref="FilterDecision.Accept"/> when matching <see cref="LevelMin"/> and <see cref="LevelMax"/>
77
 
                /// </summary>
78
 
                /// <remarks>
79
 
                /// <para>
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.
84
 
                /// </para>
85
 
                /// <para>
86
 
                /// The default is <c>true</c> i.e. to <see cref="FilterDecision.Accept"/> the event.
87
 
                /// </para>
88
 
                /// </remarks>
89
 
                public bool AcceptOnMatch
90
 
                {
91
 
                        get { return m_acceptOnMatch; }
92
 
                        set { m_acceptOnMatch = value; }
93
 
                }
94
 
 
95
 
                /// <summary>
96
 
                /// Set the minimum matched <see cref="Level"/>
97
 
                /// </summary>
98
 
                /// <remarks>
99
 
                /// <para>
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"/>.
103
 
                /// </para>
104
 
                /// </remarks>
105
 
                public Level LevelMin
106
 
                {
107
 
                        get { return m_levelMin; }
108
 
                        set { m_levelMin = value; }
109
 
                }
110
 
 
111
 
                /// <summary>
112
 
                /// Sets the maximum matched <see cref="Level"/>
113
 
                /// </summary>
114
 
                /// <remarks>
115
 
                /// <para>
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"/>.
119
 
                /// </para>
120
 
                /// </remarks>
121
 
                public Level LevelMax
122
 
                {
123
 
                        get { return m_levelMax; }
124
 
                        set { m_levelMax = value; }
125
 
                }
126
 
 
127
 
                #region Override implementation of FilterSkeleton
128
 
 
129
 
                /// <summary>
130
 
                /// Check if the event should be logged.
131
 
                /// </summary>
132
 
                /// <param name="loggingEvent">the logging event to check</param>
133
 
                /// <returns>see remarks</returns>
134
 
                /// <remarks>
135
 
                /// <para>
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.
142
 
                /// </para>
143
 
                /// </remarks>
144
 
                override public FilterDecision Decide(LoggingEvent loggingEvent) 
145
 
                {
146
 
                        if (loggingEvent == null)
147
 
                        {
148
 
                                throw new ArgumentNullException("loggingEvent");
149
 
                        }
150
 
 
151
 
                        if (m_levelMin != null) 
152
 
                        {
153
 
                                if (loggingEvent.Level < m_levelMin) 
154
 
                                {
155
 
                                        // level of event is less than minimum
156
 
                                        return FilterDecision.Deny;
157
 
                                }
158
 
                        }
159
 
 
160
 
                        if (m_levelMax != null) 
161
 
                        {
162
 
                                if (loggingEvent.Level > m_levelMax) 
163
 
                                {
164
 
                                        // level of event is greater than maximum
165
 
                                        return FilterDecision.Deny;
166
 
                                }
167
 
                        }
168
 
 
169
 
                        if (m_acceptOnMatch) 
170
 
                        {
171
 
                                // this filter set up to bypass later filters and always return
172
 
                                // accept if level in range
173
 
                                return FilterDecision.Accept;
174
 
                        }
175
 
                        else 
176
 
                        {
177
 
                                // event is ok for this filter; allow later filters to have a look..
178
 
                                return FilterDecision.Neutral;
179
 
                        }
180
 
                }
181
 
 
182
 
                #endregion
183
 
        }
184
 
}