Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.TraceSource" /> class, using the specified name for the source and the default source level at which tracing is to occur.  </summary>
        /// <param name="name">The name of the source, typically the name of the application.</param>
        /// <param name="defaultLevel">A bitwise combination of the <see cref="T:System.Diagnostics.SourceLevels" /> values that specifies the default source level at which to trace.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="name" /> is null.</exception>
        /// <exception cref="T:System.ArgumentException">
        ///   <paramref name="name" /> is an empty string ("").</exception>
        public TraceSource(string name, SourceLevels sourceLevels)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Hashtable       hashtable       = null;
            TraceSourceInfo traceSourceInfo = (hashtable == null) ? null : (hashtable[name] as TraceSourceInfo);

            source_switch = new SourceSwitch(name);
            if (traceSourceInfo == null)
            {
                listeners = new TraceListenerCollection();
                return;
            }
            source_switch.Level = traceSourceInfo.Levels;
            listeners           = traceSourceInfo.Listeners;
        }
		private void AddTraceSource (IDictionary d, Hashtable sources, XmlNode node)
		{
			string name = null;
			SourceLevels levels = SourceLevels.Error;
			StringDictionary atts = new StringDictionary ();
			foreach (XmlAttribute a in node.Attributes) {
				switch (a.Name) {
				case "name":
					name = a.Value;
					break;
				case "switchValue":
					levels = (SourceLevels) Enum.Parse (typeof (SourceLevels), a.Value);
					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 (XmlNode child in node.ChildNodes) {
				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, child);
				}
				else
					ThrowUnrecognizedNode (child);
			}
		}
        private void AddTraceSource(IDictionary d, Hashtable sources, XmlNode node)
        {
            string           name   = null;
            SourceLevels     levels = SourceLevels.Error;
            StringDictionary atts   = new StringDictionary();

            foreach (XmlAttribute a in node.Attributes)
            {
                switch (a.Name)
                {
                case "name":
                    name = a.Value;
                    break;

                case "switchValue":
                    levels = (SourceLevels)Enum.Parse(typeof(SourceLevels), a.Value);
                    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 (XmlNode child in node.ChildNodes)
            {
                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, child);
                }
                else
                {
                    ThrowUnrecognizedNode(child);
                }
            }
        }