#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 very simple filter based on matching. /// /// /// /// The filter admits two options and /// . If there is an exact match between the value /// of the option 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 the does not match then /// the result will be . /// /// /// Nicko Cadell /// Gert Driesen public class LevelMatchFilter : FilterSkeleton { #region Member Variables /// /// flag to indicate if the filter should on a match /// private bool m_acceptOnMatch = true; /// /// the to match against /// private Level m_levelToMatch; #endregion #region Constructors /// /// Default constructor /// public LevelMatchFilter() { } #endregion /// /// when matching /// /// /// /// 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; } } /// /// The that the filter will match /// /// /// /// The 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 LevelToMatch { get { return m_levelToMatch; } set { m_levelToMatch = value; } } #region Override implementation of FilterSkeleton /// /// Tests if the of the logging event matches that of the filter /// /// the event to filter /// see remarks /// /// /// If the of the event matches the level of the /// filter then the result of the function depends on the /// value of . If it is true then /// the function will return , it it is false then it /// will return . If the does not match then /// the result will be . /// /// override public FilterDecision Decide(LoggingEvent loggingEvent) { if (loggingEvent == null) { throw new ArgumentNullException("loggingEvent"); } if (m_levelToMatch != null && m_levelToMatch == loggingEvent.Level) { // Found match return m_acceptOnMatch ? FilterDecision.Accept : FilterDecision.Deny; } return FilterDecision.Neutral; } #endregion } }