diff options
author | Lluis Sanchez <lluis@novell.com> | 2004-04-06 23:05:13 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2004-04-06 23:05:13 +0400 |
commit | 14c59cfad1a213b3858b79497af4bee7e62e0a55 (patch) | |
tree | f1df0f60338f4ccf041c7a767bb7153b77bbe2e8 /mcs/class/System/System.Diagnostics | |
parent | 8f63d91200821d67e4a3d4495b3eb30818b51a53 (diff) |
* DiagnosticsConfigurationHandler.cs: If initializeData is provided, use the
constructor that only takes one string as parameter to construct the
listener. The name is set using the Name property, not the constructor.
* TextWriterTraceListener.cs: In Write*, do nothing if no writer was
provided.
svn path=/trunk/mcs/; revision=25105
Diffstat (limited to 'mcs/class/System/System.Diagnostics')
3 files changed, 42 insertions, 20 deletions
diff --git a/mcs/class/System/System.Diagnostics/ChangeLog b/mcs/class/System/System.Diagnostics/ChangeLog index 5be53f98981..fcba043c0fd 100644 --- a/mcs/class/System/System.Diagnostics/ChangeLog +++ b/mcs/class/System/System.Diagnostics/ChangeLog @@ -1,3 +1,12 @@ +2004-04-06 Lluis Sanchez Gual <lluis@ximian.com> + + * DiagnosticsConfigurationHandler.cs: If initializeData is provided, use the + constructor that only takes one string as parameter to construct the + listener. The name is set using the Name property, not the constructor. + + * TextWriterTraceListener.cs: In Write*, do nothing if no writer was + provided. + 2004-03-25 Gonzalo Paniagua Javier <gonzalo@ximian.com> * Process.cs: use the ISynchronizeInvoke object to invoke the event. diff --git a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs index 706ce06c4a9..8ad3817dd8c 100644 --- a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs +++ b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs @@ -253,20 +253,28 @@ namespace System.Diagnostics private void AddTraceListener (string name, string type, string initializeData)
{
Type t = Type.GetType (type);
- object[] args = null;
- if (initializeData == null)
- args = new object[]{name};
- else
- args = new object[]{initializeData, name};
- try {
- TraceListener l = (TraceListener) Activator.CreateInstance (t, args);
- TraceImpl.Listeners.Add (l);
+ if (t == null)
+ throw new ConfigurationException (string.Format ("Invalid Type Specified: {0}", type));
+
+ object[] args;
+ Type[] types;
+
+ if (initializeData != null) {
+ args = new object[] { initializeData };
+ types = new Type[] { typeof(string) };
}
- catch (Exception e) {
- throw new ConfigurationException (
- string.Format ("Invalid Type Specified: {0}", type),
- e);
+ else {
+ args = null;
+ types = new Type[0];
}
+
+ System.Reflection.ConstructorInfo ctor = t.GetConstructor (types);
+ if (ctor == null)
+ throw new ConfigurationException ("Couldn't find constructor for class " + type);
+
+ TraceListener l = (TraceListener) ctor.Invoke (args);
+ l.Name = name;
+ TraceImpl.Listeners.Add (l);
}
private void RemoveTraceListener (string name)
diff --git a/mcs/class/System/System.Diagnostics/TextWriterTraceListener.cs b/mcs/class/System/System.Diagnostics/TextWriterTraceListener.cs index 45dff28e9c0..af30e72f0cc 100644 --- a/mcs/class/System/System.Diagnostics/TextWriterTraceListener.cs +++ b/mcs/class/System/System.Diagnostics/TextWriterTraceListener.cs @@ -87,22 +87,27 @@ namespace System.Diagnostics { public override void Flush () { - writer.Flush (); + if (writer != null) + writer.Flush (); } public override void Write (string message) { - if (NeedIndent) - WriteIndent (); - writer.Write (message); + if (writer != null) { + if (NeedIndent) + WriteIndent (); + writer.Write (message); + } } public override void WriteLine (string message) { - if (NeedIndent) - WriteIndent (); - writer.WriteLine (message); - NeedIndent = true; + if (writer != null) { + if (NeedIndent) + WriteIndent (); + writer.WriteLine (message); + NeedIndent = true; + } } } } |