Example #1
0
 /// <summary>
 /// Adds the elements of another LoggingRuleCollection to the end of this LoggingRuleCollection.
 /// </summary>
 /// <param name="items">
 /// The LoggingRuleCollection whose elements are to be added to the end of this LoggingRuleCollection.
 /// </param>
 public virtual void AddRange(LoggingRuleCollection items)
 {
     foreach (LoggingRule item in items)
     {
         this.List.Add(item);
     }
 }
Example #2
0
        internal void GetTargetsByLevelForLogger(string name, LoggingRuleCollection rules, TargetWithFilterChain[]targetsByLevel, TargetWithFilterChain[]lastTargetsByLevel)
        {
            foreach (LoggingRule rule in rules)
            {
                if (rule.NameMatches(name))
                {
                    for (int i = 0; i <= LogLevel.MaxLevel.Ordinal; ++i)
                    {
                        if (i >= GlobalThreshold.Ordinal && rule.IsLoggingEnabledForLevel(LogLevel.FromOrdinal(i)))
                        {
                            foreach (Target target in rule.Targets)
                            {
                                TargetWithFilterChain awf = new TargetWithFilterChain(target, rule.Filters);
                                if (lastTargetsByLevel[i] != null)
                                {
                                    lastTargetsByLevel[i].Next = awf;
                                }
                                else
                                {
                                    targetsByLevel[i] = awf;
                                }
                                lastTargetsByLevel[i] = awf;
                            }
                        }
                    }

                    GetTargetsByLevelForLogger(name, rule.ChildRules, targetsByLevel, lastTargetsByLevel);

                    if (rule.Final)
                        break;
                }
            }
            for (int i = 0; i <= LogLevel.MaxLevel.Ordinal; ++i)
            {
                TargetWithFilterChain tfc = targetsByLevel[i];
                if (tfc != null)
                    tfc.PrecalculateNeedsStackTrace();
            }
        }
        private void ConfigureRulesFromElement(LoggingConfiguration config, LoggingRuleCollection rules, XmlElement element)
        {
            if (element == null)
            {
                return;
            }

            foreach (XmlElement el in PropertyHelper.GetChildElements(element, "logger"))
            {
                XmlElement ruleElement = el;

                LoggingRule rule        = new LoggingRule();
                string      namePattern = GetCaseInsensitiveAttribute(ruleElement, "name");
                if (namePattern == null)
                {
                    namePattern = "*";
                }

                string appendTo = GetCaseInsensitiveAttribute(ruleElement, "appendTo");
                if (appendTo == null)
                {
                    appendTo = GetCaseInsensitiveAttribute(ruleElement, "writeTo");
                }

                rule.LoggerNamePattern = namePattern;
                if (appendTo != null)
                {
                    foreach (string t in appendTo.Split(','))
                    {
                        string targetName = t.Trim();
                        Target target     = config.FindTargetByName(targetName);

                        if (target != null)
                        {
                            rule.Targets.Add(target);
                        }
                        else
                        {
                            throw new NLogConfigurationException("Target " + targetName + " not found.");
                        }
                    }
                }
                rule.Final = false;

                if (HasCaseInsensitiveAttribute(ruleElement, "final"))
                {
                    rule.Final = true;
                }

                if (HasCaseInsensitiveAttribute(ruleElement, "level"))
                {
                    LogLevel level = LogLevel.FromString(GetCaseInsensitiveAttribute(ruleElement, "level"));
                    rule.EnableLoggingForLevel(level);
                }
                else if (HasCaseInsensitiveAttribute(ruleElement, "levels"))
                {
                    string levelsString = GetCaseInsensitiveAttribute(ruleElement, "levels");
                    levelsString = CleanWhitespace(levelsString);

                    string[] tokens = levelsString.Split(',');
                    foreach (string s in tokens)
                    {
                        if (s != "")
                        {
                            LogLevel level = LogLevel.FromString(s);
                            rule.EnableLoggingForLevel(level);
                        }
                    }
                }
                else
                {
                    int minLevel = 0;
                    int maxLevel = LogLevel.MaxLevel.Ordinal;

                    if (HasCaseInsensitiveAttribute(ruleElement, "minlevel"))
                    {
                        minLevel = LogLevel.FromString(GetCaseInsensitiveAttribute(ruleElement, "minlevel")).Ordinal;
                    }

                    if (HasCaseInsensitiveAttribute(ruleElement, "maxlevel"))
                    {
                        maxLevel = LogLevel.FromString(GetCaseInsensitiveAttribute(ruleElement, "maxlevel")).Ordinal;
                    }

                    for (int i = minLevel; i <= maxLevel; ++i)
                    {
                        rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
                    }
                }

                foreach (XmlElement el2 in PropertyHelper.GetChildElements(ruleElement, "filters"))
                {
                    ConfigureRuleFiltersFromXmlElement(rule, el2);
                }

                ConfigureRulesFromElement(config, rule.ChildRules, ruleElement);

                rules.Add(rule);
            }
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the LoggingRuleCollection class, containing elements
 /// copied from another instance of LoggingRuleCollection
 /// </summary>
 /// <param name="items">
 /// The LoggingRuleCollection whose elements are to be added to the new LoggingRuleCollection.
 /// </param>
 public LoggingRuleCollection(LoggingRuleCollection items)
 {
     this.AddRange(items);
 }
Example #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="collection"></param>
 public Enumerator(LoggingRuleCollection collection)
 {
     this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
 }
Example #6
0
 /// <summary>
 /// Adds the elements of another LoggingRuleCollection to the end of this LoggingRuleCollection.
 /// </summary>
 /// <param name="items">
 /// The LoggingRuleCollection whose elements are to be added to the end of this LoggingRuleCollection.
 /// </param>
 public virtual void AddRange(LoggingRuleCollection items)
 {
     foreach (LoggingRule item in items)
     {
         this.List.Add(item);
     }
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the LoggingRuleCollection class, containing elements
 /// copied from another instance of LoggingRuleCollection
 /// </summary>
 /// <param name="items">
 /// The LoggingRuleCollection whose elements are to be added to the new LoggingRuleCollection.
 /// </param>
 public LoggingRuleCollection(LoggingRuleCollection items)
 {
     this.AddRange(items);
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="collection"></param>
 public Enumerator(LoggingRuleCollection collection)
 {
     this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
 }