public TraceSource(string name, SourceLevels defaultLevel) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("name"); } Hashtable sources = DiagnosticsConfiguration.Settings["sources"] as Hashtable; TraceSourceInfo info = sources != null ? sources[name] as TraceSourceInfo : null; source_switch = new SourceSwitch(name); if (info == null) { listeners = new TraceListenerCollection(); source_switch.Level = defaultLevel; } else { source_switch.Level = info.Levels; listeners = info.Listeners; } }
private void AddTraceSource (IDictionary d, Hashtable sources, XElement element) { string name = null; SourceLevels levels = SourceLevels.Error; StringDictionary atts = new StringDictionary (); foreach (XAttribute a in element.Attributes()) { switch (a.Name) { case "name": name = a.Value; break; case "switchValue": levels = (SourceLevels)Enum.Parse (typeof (SourceLevels), a.Value, false); break; default: atts[a.Name] = a.Value; break; } } if (name == null) throw new ConfigurationException ("Mandatory attribute 'name' is missing in 'source' element."); // ignore duplicate ones (no error occurs) if (sources.ContainsKey (name)) return; TraceSourceInfo sinfo = new TraceSourceInfo (name, levels, configValues); sources.Add (sinfo.Name, sinfo); foreach (XElement child in element.Elements()) { XmlNodeType t = child.NodeType; if (t == XmlNodeType.Whitespace || t == XmlNodeType.Comment) continue; if (t == XmlNodeType.Element) { if (child.Name == "listeners") AddTraceListeners (d, child, sinfo.Listeners); else ThrowUnrecognizedElement (child); ValidateInvalidAttributes (child.Attributes ().ToDictionary (a => a.Name), child); } else ThrowUnrecognizedNode (child); } }
private void AddTraceSource(IDictionary d, Hashtable sources, XElement element) { string name = null; SourceLevels levels = SourceLevels.Error; StringDictionary atts = new StringDictionary(); foreach (XAttribute a in element.Attributes()) { switch (a.Name) { case "name": name = a.Value; break; case "switchValue": levels = (SourceLevels)Enum.Parse(typeof(SourceLevels), a.Value, false); break; default: atts[a.Name] = a.Value; break; } } if (name == null) { throw new ConfigurationException("Mandatory attribute 'name' is missing in 'source' element."); } // ignore duplicate ones (no error occurs) if (sources.ContainsKey(name)) { return; } TraceSourceInfo sinfo = new TraceSourceInfo(name, levels, configValues); sources.Add(sinfo.Name, sinfo); foreach (XElement child in element.Elements()) { XmlNodeType t = child.NodeType; if (t == XmlNodeType.Whitespace || t == XmlNodeType.Comment) { continue; } if (t == XmlNodeType.Element) { if (child.Name == "listeners") { AddTraceListeners(d, child, sinfo.Listeners); } else { ThrowUnrecognizedElement(child); } ValidateInvalidAttributes(child.Attributes().ToDictionary(a => a.Name), child); } else { ThrowUnrecognizedNode(child); } } }