#region Apache License // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to you under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #endregion using System; using log4net; using log4net.Core; using log4net.Util; namespace log4net.Filter { /// /// This is a simple filter based on matching. /// /// /// /// The filter admits three options and /// that determine the range of priorities that are matched, and /// . If there is a match between the range /// of priorities and the of the , then the /// method returns in case the /// option value is set to true, if it is false /// then is returned. If there is no match, is returned. /// /// /// Nicko Cadell /// Gert Driesen public class LevelRangeFilter : FilterSkeleton { #region Member Variables /// /// Flag to indicate the behavior when matching a /// private bool m_acceptOnMatch = true; /// /// the minimum value to match /// private Level m_levelMin; /// /// the maximum value to match /// private Level m_levelMax; #endregion #region Constructors /// /// Default constructor /// public LevelRangeFilter() { } #endregion /// /// when matching and /// /// /// /// The property is a flag that determines /// the behavior when a matching is found. If the /// flag is set to true then the filter will the /// logging event, otherwise it will the event. /// /// /// The default is true i.e. to the event. /// /// public bool AcceptOnMatch { get { return m_acceptOnMatch; } set { m_acceptOnMatch = value; } } /// /// Set the minimum matched /// /// /// /// The minimum level that this filter will attempt to match against the /// level. If a match is found then /// the result depends on the value of . /// /// public Level LevelMin { get { return m_levelMin; } set { m_levelMin = value; } } /// /// Sets the maximum matched /// /// /// /// The maximum level that this filter will attempt to match against the /// level. If a match is found then /// the result depends on the value of . /// /// public Level LevelMax { get { return m_levelMax; } set { m_levelMax = value; } } #region Override implementation of FilterSkeleton /// /// Check if the event should be logged. /// /// the logging event to check /// see remarks /// /// /// If the of the logging event is outside the range /// matched by this filter then /// is returned. If the is matched then the value of /// is checked. If it is true then /// is returned, otherwise /// is returned. /// /// override public FilterDecision Decide(LoggingEvent loggingEvent) { if (loggingEvent == null) { throw new ArgumentNullException("loggingEvent"); } if (m_levelMin != null) { if (loggingEvent.Level < m_levelMin) { // level of event is less than minimum return FilterDecision.Deny; } } if (m_levelMax != null) { if (loggingEvent.Level > m_levelMax) { // level of event is greater than maximum return FilterDecision.Deny; } } if (m_acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return FilterDecision.Accept; } else { // event is ok for this filter; allow later filters to have a look.. return FilterDecision.Neutral; } } #endregion } }