/// <summary> /// 解析日志 /// </summary> /// <param name="curElement"></param> private void ParseLogger(XmlElement curElement) { i++; LogConfigSetting logConfigSetting = new LogConfigSetting(); string loggerName = curElement.Attributes["name"].Value.ToLower(); if (String.IsNullOrEmpty(loggerName)) { loggerName = "defaultLogger" + i; } logConfigSetting.loggerName = loggerName; foreach (XmlNode twoLevelNode in curElement.ChildNodes) { if (twoLevelNode.NodeType == XmlNodeType.Element) { XmlElement element = twoLevelNode as XmlElement; switch (element.Name.ToLower()) { case "level": string level = element.GetAttribute("value").ToLower(); switch (level) { case "all": logConfigSetting.logLevel = LogLevel.All; break; case "info": logConfigSetting.logLevel = LogLevel.Info; break; case "warn": logConfigSetting.logLevel = LogLevel.Warn; break; case "error": logConfigSetting.logLevel = LogLevel.Error; break; default: logConfigSetting.logLevel = LogLevel.All; break; } break; case "writer": logConfigSetting.writerNames.Add(element.GetAttribute("ref").ToLower()); break; } } } defChildLoggers.Add(logConfigSetting); }
public static LogConfigSetting[] GetSection() { Configuration config = UtilSystem.getCurrentConfig(); ConfigurationSectionGroup oSectionGroup = config.SectionGroups[defaultSectionName]; if ((oSectionGroup != null) && (oSectionGroup.Sections.Count > 0)) { LogConfigSetting[] logConfigSettings = new LogConfigSetting[oSectionGroup.Sections.Count]; LogConfigSetting logConfigSetting = null; for (int i = 0; i < oSectionGroup.Sections.Count; i++) { logConfigSetting = (LogConfigSetting)config.GetSection(defaultSectionName + "/" + oSectionGroup.Sections.Keys.Get(i)); try { List<IWriter> writers = new List<IWriter>(); TextWriter textWriter = new TextWriter(); textWriter.FileName = logConfigSetting.fileName; textWriter.LogPath = ConfigurationSectionHandler.LogPathInfo + logConfigSetting.logPath; writers.Add(textWriter); logConfigSetting.writers = writers; } catch { //出现异常,填充默认的日志 logConfigSetting.loggerName = ""; logConfigSetting.logLevel = LogLevel.All; List<IWriter> writers = new List<IWriter>(); TextWriter textWriter = new TextWriter(); textWriter.FileName = "xiben.log"; textWriter.LogPath = @"C:\xiben\Temp"; writers.Add(textWriter); logConfigSetting.writers = writers; } logConfigSettings[i] = logConfigSetting; } return logConfigSettings; } return null; }
public static LogConfigSetting[] GetSection() { Configuration config = UtilSystem.getCurrentConfig(); ConfigurationSectionGroup oSectionGroup = config.SectionGroups[defaultSectionName]; if ((oSectionGroup != null) && (oSectionGroup.Sections.Count > 0)) { LogConfigSetting[] logConfigSettings = new LogConfigSetting[oSectionGroup.Sections.Count]; LogConfigSetting logConfigSetting = null; for (int i = 0; i < oSectionGroup.Sections.Count; i++) { logConfigSetting = (LogConfigSetting)config.GetSection(defaultSectionName + "/" + oSectionGroup.Sections.Keys.Get(i)); try { List <IWriter> writers = new List <IWriter>(); TextWriter textWriter = new TextWriter(); textWriter.FileName = logConfigSetting.fileName; textWriter.LogPath = ConfigurationSectionHandler.LogPathInfo + logConfigSetting.logPath; writers.Add(textWriter); logConfigSetting.writers = writers; } catch { //出现异常,填充默认的日志 logConfigSetting.loggerName = ""; logConfigSetting.logLevel = LogLevel.All; List <IWriter> writers = new List <IWriter>(); TextWriter textWriter = new TextWriter(); textWriter.FileName = "xiben.log"; textWriter.LogPath = @"C:\xiben\Temp"; writers.Add(textWriter); logConfigSetting.writers = writers; } logConfigSettings[i] = logConfigSetting; } return(logConfigSettings); } return(null); }