[ 
https://issues.apache.org/jira/browse/LOG4NET-108?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16436315#comment-16436315
 ] 

Michael Schall commented on LOG4NET-108:
----------------------------------------

I realize this is an old ticket.  However we needed something like this to 
trigger the evaluator on a Level or a custom property.  I implemented Nicko 
Cadell's idea of a collection of evaluators.

Below is our implementation of a MultipleEvaluator.  It has a list of 
evaluators and can be in Any or All mode.

*MultipleEvaluator.cs*
{code:java}
    public class MultipleEvaluator : ITriggeringEventEvaluator {

        public enum MultipleEvaluatorMode {
            Any,
            All
        }

        private readonly List<ITriggeringEventEvaluator> _evaluators = new 
List<ITriggeringEventEvaluator>();

        public MultipleEvaluatorMode Mode { get; set; } = 
MultipleEvaluatorMode.Any;

        public void AddEvaluator(ITriggeringEventEvaluator evaluator) {
            _evaluators.Add(evaluator);
        }

        public bool IsTriggeringEvent(LoggingEvent loggingEvent) {
            switch (Mode) {
                case MultipleEvaluatorMode.Any:
                    return _evaluators.Any(e => 
e.IsTriggeringEvent(loggingEvent));
                case MultipleEvaluatorMode.All:
                    return _evaluators.All(e => 
e.IsTriggeringEvent(loggingEvent));
                default:
                    throw new Exception("unknown mode: " + Mode);
            }
        }

    }
 {code}
We also created the following where you can specify a name/value of a property 
that will trigger a flush (if value is not set it will trigger if the name is 
present).

*PropertyValueEvaluator.cs*
{code:java}
    public class PropertyValueEvaluator : ITriggeringEventEvaluator {

        public string Name { get; set; }

        public object Value { get; set; }

        public bool IsTriggeringEvent(LoggingEvent loggingEvent) {
            if (Value == null) {
                return loggingEvent.Properties.Contains(Name);
            }
            return Equals(loggingEvent.Properties[Name], Value);
        }

    }
{code}
This can then be configured with the following xml (assuming the two new 
Evaluators are in the log4net.Core namespace)
{code:xml}
        <evaluator type="log4net.Core.MultipleEvaluator">
            <evaluator type="log4net.Core.LevelEvaluator">
                <threshold value="WARN"/>
            </evaluator>
            <evaluator type="log4net.Core.PropertyValueEvaluator">
                <name value="TriggerToServer"/>
            </evaluator>
        </evaluator>
{code}

> [PATCH] add support for multiple evaluators in BufferingAppenderSkeletan
> ------------------------------------------------------------------------
>
>                 Key: LOG4NET-108
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-108
>             Project: Log4net
>          Issue Type: Improvement
>          Components: Appenders, Core
>    Affects Versions: 1.2.10
>            Reporter: Drew Schaeffer
>            Assignee: Nicko Cadell
>            Priority: Minor
>             Fix For: 1.2/2.0 Maintenance Release
>
>         Attachments: EvaluatorCollection.cs, patch-file.diff
>
>
> Currently BufferedAppenders only have support for one evaluator and one lossy 
> evaluator.  This is fine when the only available evaluator is LevelEvaluator 
> (as multriple LevelEvaluators do not make sense) but with the addition of 
> ExceptionEvaluator (LOG4NET-107) it would be nice for 
> BufferingAppenderSkeletan to have a collection of evaluators.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to