/// <summary> /// 从指定的配置对象获取AppLogger配置组对象 /// </summary> /// <param name="config">配置对象,不能为null。</param> /// <returns> /// AppLogger配置组对象,不会为null。 /// </returns> /// <exception cref="System.ArgumentNullException">config对象为null。</exception> /// <exception cref="ArgumentException">config中未找到对应的配置组节点。</exception> public static AppLoggerSectionGroup GetSectionGroup(System.Configuration.Configuration config) { if (config == null) { throw new ArgumentNullException(); } ConfigurationSectionGroup group = null; AppLoggerSectionGroup appLoggerGroup = null; //group = config.SectionGroups["USe.Common.AppLogger"]; foreach (ConfigurationSectionGroup g in config.SectionGroups) { if (g.Name == "USe.Common.AppLogger") { group = g; break; } } if (group == null) { throw new ArgumentException("Not found the special configuration section group."); } appLoggerGroup = group as AppLoggerSectionGroup; Debug.Assert(appLoggerGroup != null); return(appLoggerGroup); }
/// <summary> /// 使用指定的配置元素名称查找对应的应用程序日志配置参数对象。 /// </summary> /// <param name="elementName">配置元素名称,大小写敏感。</param> /// <returns> /// 应用程序日志配置参数对象,未找到时返回null。 /// </returns> public static AppLoggerElement FindAppLoggerElement(string elementName) { AppLoggerSectionGroup group = GetSectionGroup(); Debug.Assert(group != null); AppLoggerElement result = null; foreach (AppLoggerElement e in group.AppLoggers.AppLoggers) { if (e.Name == elementName) { result = e; break; } } return(result); }