2007-05-18 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 18 May 2007 13:52:06 +0000 (13:52 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 18 May 2007 13:52:06 +0000 (13:52 -0000)
* TraceSourceInfo.cs : new class for storing configuration data.
* TraceSource.cs : TraceEventCache arguments should be null (they are
  nullable). Use TraceSourceInfo above.
* DiagnosticsConfigurationHandler.cs : removed hack to store listeners
  in named sources, not traceimpl. Create TraceSource objects from
  configuration data.

* System.dll.sources : added TraceSourceInfo.cs.

svn path=/trunk/mcs/; revision=77640

mcs/class/System/ChangeLog
mcs/class/System/System.Diagnostics/ChangeLog
mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs
mcs/class/System/System.Diagnostics/TraceSource.cs
mcs/class/System/System.Diagnostics/TraceSourceInfo.cs [new file with mode: 0644]
mcs/class/System/System.dll.sources

index fa60540408b06e373ce2ba0c1e80e7e545dbbc5b..05099b7dc0187b20bd30fa92f8476a9fc5e792eb 100644 (file)
@@ -1,3 +1,7 @@
+2007-05-18  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * System.dll.sources : added TraceSourceInfo.cs.
+
 2007-05-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * System.dll.sources : added TraceOptions.cs.
index e95089c11273ec784139348b6dc2b166eb45de09..2bfc2ec6bfdbb345acac9f66789d74811a5b93c4 100644 (file)
@@ -1,8 +1,17 @@
+2007-05-18  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * TraceSourceInfo.cs : new class for storing configuration data.
+       * TraceSource.cs : TraceEventCache arguments should be null (they are
+         nullable). Use TraceSourceInfo above.
+       * DiagnosticsConfigurationHandler.cs : removed hack to store listeners
+         in named sources, not traceimpl. Create TraceSource objects from
+         configuration data.
+
 2007-05-18  Marek Safar  <marek.safar@gmail.com>
 
        * DiagnosticsConfigurationHandler.cs: Fixed 1.1 build.
 
-2007-05-19  Atsushi Enomoto  <atsushi@ximian.com>
+2007-05-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlWriterTraceListener.cs : open file in shared r/w mode.
        * DiagnosticsConfigurationHandler.cs : process <sharedListeners>
@@ -10,7 +19,7 @@
        * EventLogTraceListener.cs : added 2.0 stubs.
        * CorrelationManager.cs : removed todo.
 
-2007-05-19  Atsushi Enomoto  <atsushi@ximian.com>
+2007-05-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * TraceListener.cs : in TraceTransfer(), use TraceEvent() (some
          derived classes depend on this change).
index 505381cf17521c336f9657e8dd2a54222667851e..a1b8afd8c01789235d3093f2c435456763f13aa5 100644 (file)
@@ -94,7 +94,6 @@ namespace System.Diagnostics
                        elementHandlers ["trace"] = new ElementHandler (AddTraceNode);
 #if NET_2_0
                        elementHandlers ["sources"] = new ElementHandler (AddSourcesNode);
-                       //elementHandlers ["sharedListeners"] = new ElementHandler (AddSharedListenersNode);
 #endif
                }
 
@@ -113,7 +112,7 @@ namespace System.Diagnostics
                                case XmlNodeType.Element:
                                        if (child.LocalName != "sharedListeners")
                                                continue;
-                                       AddSharedListenersNode (d, child);
+                                       AddTraceListeners (d, child, GetSharedListeners (d));
                                        break;
                                }
                        }
@@ -247,7 +246,7 @@ namespace System.Diagnostics
                                        continue;
                                if (t == XmlNodeType.Element) {
                                        if (child.Name == "listeners")
-                                               AddTraceListeners (d, child);
+                                               AddTraceListeners (d, child, TraceImpl.Listeners);
                                        else
                                                ThrowUnrecognizedElement (child);
                                        ValidateInvalidAttributes (child.Attributes, child);
@@ -292,8 +291,6 @@ namespace System.Diagnostics
                }
 
 #if NET_2_0
-               static readonly Hashtable static_sources = new Hashtable ();
-
                private TraceListenerCollection GetSharedListeners (IDictionary d)
                {
                        TraceListenerCollection shared_listeners = d ["sharedListeners"] as TraceListenerCollection;
@@ -304,12 +301,6 @@ namespace System.Diagnostics
                        return shared_listeners;
                }
 
-               private void AddSharedListenersNode (IDictionary d, XmlNode node)
-               {
-                       TraceListenerCollection shared_listeners = GetSharedListeners (d);
-                       AddTraceListenersTo (d, node, shared_listeners);
-               }
-
                private void AddSourcesNode (IDictionary d, XmlNode node)
                {
                        // FIXME: are there valid attributes?
@@ -319,8 +310,6 @@ namespace System.Diagnostics
                                sources = new Hashtable ();
                                d ["sources"] = sources;
                        }
-                       // FIXME: here I replace the table with fake static variable.
-                       sources = static_sources;
 
                        foreach (XmlNode child in node.ChildNodes) {
                                XmlNodeType t = child.NodeType;
@@ -359,12 +348,12 @@ namespace System.Diagnostics
                        if (name == null)
                                throw new ConfigurationException ("Mandatory attribute 'name' is missing in 'source' element.");
 
-                       // FIXME: it should raise an error for duplicate name sources.
+                       // ignore duplicate ones (no error occurs)
                        if (sources.ContainsKey (name))
                                return;
 
-                       TraceSource source = new TraceSource (name, levels);
-                       sources.Add (source.Name, source);
+                       TraceSourceInfo sinfo = new TraceSourceInfo (name, levels);
+                       sources.Add (sinfo.Name, sinfo);
                        
                        foreach (XmlNode child in node.ChildNodes) {
                                XmlNodeType t = child.NodeType;
@@ -372,7 +361,7 @@ namespace System.Diagnostics
                                        continue;
                                if (t == XmlNodeType.Element) {
                                        if (child.Name == "listeners")
-                                               AddTraceListeners (d, child);
+                                               AddTraceListeners (d, child, sinfo.Listeners);
                                        else
                                                ThrowUnrecognizedElement (child);
                                        ValidateInvalidAttributes (child.Attributes, child);
@@ -384,13 +373,8 @@ namespace System.Diagnostics
 #endif
 
                // only defines "add" and "remove", but "clear" also works
-               // for add, "name" and "type" are required; initializeData is optional
-               private void AddTraceListeners (IDictionary d, XmlNode listenersNode)
-               {
-                       AddTraceListenersTo (d, listenersNode, TraceImpl.Listeners);
-               }
-
-               private void AddTraceListenersTo (IDictionary d, XmlNode listenersNode, TraceListenerCollection listeners)
+               // for add, "name" is required; initializeData is optional; "type" is required in 1.x, optional in 2.0.
+               private void AddTraceListeners (IDictionary d, XmlNode listenersNode, TraceListenerCollection listeners)
                {
 #if !TARGET_JVM
                        // There are no attributes on <listeners/>
index c1142c437b16b1ee187ec1c5f3f518fe58755628..52eb37f4d8823a989a9551de3ff45022e882f6a4 100644 (file)
 using System;
 using System.Collections;
 using System.Collections.Specialized;
+using System.Configuration;
 
 namespace System.Diagnostics
 {
        public class TraceSource
        {
                SourceSwitch source_switch;
-               TraceListenerCollection listeners =
-                       new TraceListenerCollection ();
-               TraceEventCache cache = new TraceEventCache ();
+               TraceListenerCollection listeners;
 
                public TraceSource (string name)
                        : this (name, SourceLevels.Off)
@@ -52,8 +51,16 @@ namespace System.Diagnostics
                {
                        if (name == null)
                                throw new ArgumentNullException ("name");
+                       Hashtable sources = DiagnosticsConfiguration.Settings ["sources"] as Hashtable;
+                       TraceSourceInfo info = sources != null ? sources [name] as TraceSourceInfo : null;
                        source_switch = new SourceSwitch (name);
-                       source_switch.Level = sourceLevels;
+
+                       if (info == null)
+                               listeners = new TraceListenerCollection ();
+                       else {
+                               source_switch.Level = info.Levels;
+                               listeners = info.Listeners;
+                       }
                }
 
                public StringDictionary Attributes {
@@ -101,7 +108,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceData (cache, Name, eventType, id, data);
+                                       tl.TraceData (null, Name, eventType, id, data);
                        }
                }
 
@@ -113,7 +120,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceData (cache, Name, eventType, id, data);
+                                       tl.TraceData (null, Name, eventType, id, data);
                        }
                }
 
@@ -124,7 +131,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceEvent (cache, Name, eventType, id);
+                                       tl.TraceEvent (null, Name, eventType, id);
                        }
                }
 
@@ -136,7 +143,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceEvent (cache, Name, eventType, id, message);
+                                       tl.TraceEvent (null, Name, eventType, id, message);
                        }
                }
 
@@ -148,7 +155,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceEvent (cache, Name, eventType, id, format, args);
+                                       tl.TraceEvent (null, Name, eventType, id, format, args);
                        }
                }
 
@@ -172,7 +179,7 @@ namespace System.Diagnostics
                                return;
                        lock (((ICollection) listeners).SyncRoot) {
                                foreach (TraceListener tl in listeners)
-                                       tl.TraceTransfer (cache, Name, id, message, relatedActivityId);
+                                       tl.TraceTransfer (null, Name, id, message, relatedActivityId);
                        }
                }
 
diff --git a/mcs/class/System/System.Diagnostics/TraceSourceInfo.cs b/mcs/class/System/System.Diagnostics/TraceSourceInfo.cs
new file mode 100644 (file)
index 0000000..910e90b
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// TraceSourceInfo.cs
+//
+// Author: 
+//     Atsushi Enomoto  <atsushi@ximian.com>
+//
+// (C) 2007 Novell, Inc.  http://www.novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+#if NET_2_0
+
+using System;
+using System.Diagnostics;
+
+namespace System.Diagnostics
+{
+       internal class TraceSourceInfo
+       {
+               string name;
+               SourceLevels levels;
+               TraceListenerCollection listeners = new TraceListenerCollection ();
+
+               public TraceSourceInfo (string name, SourceLevels levels)
+               {
+                       this.name = name;
+                       this.levels = levels;
+               }
+
+               public string Name {
+                       get { return name; }
+               }
+
+               public SourceLevels Levels {
+                       get { return levels; }
+               }
+
+               public TraceListenerCollection Listeners {
+                       get { return listeners; }
+               }
+       }
+}
+
+#endif
index 5e71ed3324bd72e8243104469e8f1c928f2062e7..cc938d78eff1abb291a707d30315e50358d6f311 100644 (file)
@@ -520,6 +520,7 @@ System.Diagnostics/TraceListenerCollection.cs
 System.Diagnostics/TraceListener.cs
 System.Diagnostics/TraceOptions.cs
 System.Diagnostics/TraceSource.cs
+System.Diagnostics/TraceSourceInfo.cs
 System.Diagnostics/TraceSwitch.cs
 System.Diagnostics/Win32EventLog.cs
 System.Diagnostics/XmlWriterTraceListener.cs