private void ConfigureRulesFromElement(XmlElement element) { if (element == null) return; foreach (XmlElement ruleElement in element.GetElementsByTagName("logger")) { AppenderRule rule = new AppenderRule(); string namePattern = ruleElement.GetAttribute("name"); string appendTo = ruleElement.GetAttribute("appendTo"); rule.LoggerNamePattern = namePattern; foreach (string appenderName in appendTo.Split(',')) { rule.AppenderNames.Add(appenderName.Trim()); } rule.Final = false; if (ruleElement.HasAttribute("final")) { rule.Final = true; } if (ruleElement.HasAttribute("level")) { LogLevel level = LogLevelFromString(ruleElement.GetAttribute("level")); rule.EnableLoggingForLevel(level); } else if (ruleElement.HasAttribute("levels")) { string levelsString = ruleElement.GetAttribute("levels"); levelsString = CleanWhitespace(levelsString); string[] tokens = levelsString.Split(','); foreach (string s in tokens) { LogLevel level = LogLevelFromString(s); rule.EnableLoggingForLevel(level); } } else { int minLevel = 0; int maxLevel = (int)LogLevel.MaxLevel; if (ruleElement.HasAttribute("minlevel")) { minLevel = (int)LogLevelFromString(ruleElement.GetAttribute("minlevel")); } if (ruleElement.HasAttribute("maxlevel")) { maxLevel = (int)LogLevelFromString(ruleElement.GetAttribute("maxlevel")); } for (int i = minLevel; i <= maxLevel; ++i) { rule.EnableLoggingForLevel((LogLevel)i); } } AppenderRules.Add(rule); } }
public void AddAppenderRule(AppenderRule rule) { _appenderRules.Add(rule); }