* 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
+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.
+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>
* 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).
elementHandlers ["trace"] = new ElementHandler (AddTraceNode);
#if NET_2_0
elementHandlers ["sources"] = new ElementHandler (AddSourcesNode);
- //elementHandlers ["sharedListeners"] = new ElementHandler (AddSharedListenersNode);
#endif
}
case XmlNodeType.Element:
if (child.LocalName != "sharedListeners")
continue;
- AddSharedListenersNode (d, child);
+ AddTraceListeners (d, child, GetSharedListeners (d));
break;
}
}
continue;
if (t == XmlNodeType.Element) {
if (child.Name == "listeners")
- AddTraceListeners (d, child);
+ AddTraceListeners (d, child, TraceImpl.Listeners);
else
ThrowUnrecognizedElement (child);
ValidateInvalidAttributes (child.Attributes, child);
}
#if NET_2_0
- static readonly Hashtable static_sources = new Hashtable ();
-
private TraceListenerCollection GetSharedListeners (IDictionary d)
{
TraceListenerCollection shared_listeners = d ["sharedListeners"] as TraceListenerCollection;
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?
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;
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;
continue;
if (t == XmlNodeType.Element) {
if (child.Name == "listeners")
- AddTraceListeners (d, child);
+ AddTraceListeners (d, child, sinfo.Listeners);
else
ThrowUnrecognizedElement (child);
ValidateInvalidAttributes (child.Attributes, child);
#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/>
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)
{
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 {
return;
lock (((ICollection) listeners).SyncRoot) {
foreach (TraceListener tl in listeners)
- tl.TraceData (cache, Name, eventType, id, data);
+ tl.TraceData (null, Name, eventType, id, data);
}
}
return;
lock (((ICollection) listeners).SyncRoot) {
foreach (TraceListener tl in listeners)
- tl.TraceData (cache, Name, eventType, id, data);
+ tl.TraceData (null, Name, eventType, id, data);
}
}
return;
lock (((ICollection) listeners).SyncRoot) {
foreach (TraceListener tl in listeners)
- tl.TraceEvent (cache, Name, eventType, id);
+ tl.TraceEvent (null, Name, eventType, id);
}
}
return;
lock (((ICollection) listeners).SyncRoot) {
foreach (TraceListener tl in listeners)
- tl.TraceEvent (cache, Name, eventType, id, message);
+ tl.TraceEvent (null, Name, eventType, id, message);
}
}
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);
}
}
return;
lock (((ICollection) listeners).SyncRoot) {
foreach (TraceListener tl in listeners)
- tl.TraceTransfer (cache, Name, id, message, relatedActivityId);
+ tl.TraceTransfer (null, Name, id, message, relatedActivityId);
}
}
--- /dev/null
+//
+// 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
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