Browse Source

*** empty log message ***

svn path=/trunk/mcs/; revision=3036
Jonathan Pryor 24 years ago
parent
commit
b83ce684ef

+ 305 - 407
mcs/class/System/System.Diagnostics/Debug.cs

@@ -1,407 +1,305 @@
-//
-// System.Diagnostics.Debug.cs
-//
-// Author: John R. Hicks <[email protected]>
-//
-// (C) 2002
-//
-using System;
-
-namespace System.Diagnostics
-{
-	
-	/// <summary>
-	/// Provides a set of methods to help debug code
-	/// </summary>
-	public sealed class Debug
-	{
-		private static bool autoFlush;
-		private static int indentLevel;
-		private static int indentSize;
-		private static TraceListenerCollection listeners;
-		
-		static Debug()
-		{
-			autoFlush = false;
-			indentLevel = 0;
-			indentSize = 4;
-			listeners = new TraceListenerCollection();
-		}
-		
-		/// <summary>
-		/// Gets or sets value indicating whether Flush should
-		/// be called on the listeners.
-		/// </summary>
-		public static bool AutoFlush
-		{
-			get
-			{
-				return autoFlush;
-			}
-			set
-			{
-				autoFlush = value;
-			}
-		}
-		
-		/// <summary>
-		/// Gets or sets indent level
-		/// </summary>
-		public static int IndentLevel
-		{
-			get
-			{
-				return indentLevel;
-			}
-			set
-			{
-				indentLevel = value;
-			}
-		}
-		
-		/// <summary>
-		/// The number of spaces in an indent.
-		/// </summary>
-		public static int IndentSize
-		{
-			get
-			{
-				return indentSize;
-			}
-			set
-			{
-				indentSize = value;
-			}
-		}
-		
-		/// <summary>
-		/// Returns the listeners collection
-		/// </summary>
-		public static TraceListenerCollection Listeners
-		{
-			get
-			{
-				return listeners;
-			}
-		}
-		
-		/// <summary>
-		/// Checks for a condition, and prints a stack trace
-		/// if the condition is false.
-		/// </summary>
-		public static void Assert(bool condition)
-		{
-			if(!condition) {
-				WriteLine(new StackTrace().ToString());		
-			}
-			
-		}
-		
-		/// <summary>
-		/// Checks for a condition, and displays a message if the condition
-		/// is false.
-		/// </summary>
-		public static void Assert(bool condition, string message)
-		{
-			if(!condition) {
-				WriteLine(message);		
-				
-			}
-			
-		}
-		
-		/// <summary>
-		/// Checks for a condtion, and displays a message and a detailed message
-		/// string if the condition is false.
-		/// </summary>
-		public static void Assert(bool condition, string message, string detailMessage)
-		{
-			if(!condition) {
-				WriteLine(message);
-				Indent();
-				WriteLine(detailMessage);
-				Unindent();
-				
-			}
-		}
-		
-		/// <summary>
-		/// Closes the Debug buffer
-		/// </summary>
-		public static void Close()
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Close();
-			}
-		}
-		
-		/// <summary>
-		/// Emits the specified error message.
-		/// </summary>
-		public static void Fail(string message)
-		{
-			WriteLine(message);
-			
-		}
-		
-		/// <summary>
-		/// Emits the specified error message and detailed error message.
-		/// </summary>
-		public static void Fail(string message, string detailMessage)
-		{
-			WriteLine(message);
-			Indent();
-			WriteLine(detailMessage);
-			Unindent();
-			
-		}
-		
-		/// <summary>
-		/// Flushes the listeners
-		/// </summary>
-		public static void Flush()
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Flush();
-			}
-		}
-		
-		/// <summary>
-		/// Increments the indent level
-		/// </summary>
-		public static void Indent()
-		{
-			indentLevel++;	
-		}
-		
-		/// <summary>
-		/// Decrements the indent level
-		/// </summary>
-		public static void Unindent()
-		{
-			if(indentLevel == 0)
-				return;
-			else
-				indentLevel--;
-		}
-		
-		/// <summary>
-		/// Writes the value of the specified object's ToString method
-		/// to the listeners.
-		/// </summary>
-		public static void Write(object value)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Write(value.ToString());
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified message to each listener in the Listeners collection.
-		/// </summary>
-		public static void Write(string message)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Write(message);
-			}
-		}
-		
-		/// <summary>
-		/// Writes the category name and value of the specified object's
-		/// ToString method to each listener in the Listeners collection.
-		/// </summary>
-		public static void Write(object value, string category)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Write("[" + category + "] " + value.ToString());
-			}
-		}
-		
-		/// <summary>
-		/// Writes the category name and the specified message
-		/// to each listener in the Listeners collection.
-		/// </summary>
-		public static void Write(string message, string category)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.Write("[" + category + "] " + message);
-			}
-		}
-		
-		/// <summary>
-		/// Writes the value of the specified object's ToString method
-		/// to each of the listeners if the condition is true.
-		/// </summary>
-		public static void WriteIf(bool condition, object value)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.Write(value.ToString());
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified message to each of the listeners
-		/// if the specified condition is true.
-		/// </summary>
-		public static void WriteIf(bool condition, string message)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.Write(message);
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the value of the specified object's ToString message
-		/// and category to each of the listeners if the condition is true.
-		/// </summary>
-		public static void WriteIf(bool condition, object value, string category)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.Write("[" + category + "] " + value.ToString());
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the category and specified message to each listener
-		/// if the specified condition is true.
-		/// </summary>
-		public static void WriteIf(bool condition, string message, string category)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.Write("[" + category + "] " + message);
-				}
-			}
-			
-		}
-		
-		/// <summary>
-		/// Writes the value of the object's ToString method,
-		/// followed by a line terminator, to each listener.
-		/// </summary>
-		public static void WriteLine(object value)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.WriteLine(value.ToString());
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified message, followed by a line terminator,
-		/// to each listener.
-		/// </summary>
-		public static void WriteLine(string message)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.WriteLine(message);
-			}
-		}
-		
-		/// <summary>
-		/// Writes the value of the specified object's ToString method,
-		/// along with a category, followed by a line terminator, to each listener.
-		/// </summary>
-		public static void WriteLine(object value, string category)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.WriteLine("[" + category + "] " + value.ToString());
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified category and message, followed by a line terminator,
-		/// to each listener.
-		/// </summary>
-		public static void WriteLine(string message, string category)
-		{
-			foreach(TraceListener l in listeners)
-			{
-				l.WriteLine("[" + category + "] " + message);
-			}
-		}
-		
-		/// <summary>
-		/// Writes the value of the object's ToString method
-		/// to each listener if the specified condition is true.
-		/// </summary>
-		public static void WriteLineIf(bool condition, object value)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.WriteLine(value.ToString());
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified message to each listener
-		/// if the specified condition is true.
-		/// </summary>
-		public static void WriteLineIf(bool condition, string message)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.WriteLine(message);
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the value of the object's ToString method, and a category
-		/// to each listener if the specified condition is true.
-		/// </summary>
-		public static void WriteLineIf(bool condition, object value, string category)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.WriteLine("[" + category + "] " + value.ToString());
-				}
-			}
-		}
-		
-		/// <summary>
-		/// Writes the specified category and message to each listener, followed by a line
-		/// terminator, if the specified condition is true.
-		/// </summary>
-		public static void WriteLineIf(bool condition, string message, string category)
-		{
-			if(condition)
-			{
-				foreach(TraceListener l in listeners)
-				{
-					l.WriteLine("[" + category + "] " + message);
-				}
-			}
-			
-		}
-	}
-}
+//
+// System.Diagnostics.Debug.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002
+//
+
+using System;
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+	/// <summary>
+	/// Provides a set of methods to help debug code
+	/// </summary>
+	public sealed class Debug {
+
+		/// <summary>
+		/// Gets or sets value indicating whether Flush should
+		/// be called on the listeners.
+		/// </summary>
+		public static bool AutoFlush {
+			get {return TraceImpl.AutoFlush;}
+			set {TraceImpl.AutoFlush = value;}
+		}
+
+		/// <summary>
+		/// Gets or sets indent level
+		/// </summary>
+		public static int IndentLevel {
+			get {return TraceImpl.IndentLevel;}
+			set {TraceImpl.IndentLevel = value;}
+		}
+
+		/// <summary>
+		/// The number of spaces in an indent.
+		/// </summary>
+		public static int IndentSize {
+			get {return TraceImpl.IndentSize;}
+			set {TraceImpl.IndentSize = value;}
+		}
+
+		/// <summary>
+		/// Returns the listeners collection
+		/// </summary>
+		public static TraceListenerCollection Listeners {
+			get {return TraceImpl.Listeners;}
+		}
+
+		/// <summary>
+		/// Checks for a condition, and prints a stack trace
+		/// if the condition is false.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Assert (bool condition)
+		{
+			TraceImpl.Assert (condition);
+		}
+
+		/// <summary>
+		/// Checks for a condition, and displays a message if the condition
+		/// is false.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Assert (bool condition, string message)
+		{
+			TraceImpl.Assert (condition, message);
+		}
+
+		/// <summary>
+		/// Checks for a condtion, and displays a message and a detailed message
+		/// string if the condition is false.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Assert (bool condition, string message, 
+			string detailMessage)
+		{
+			TraceImpl.Assert (condition, message, detailMessage);
+		}
+
+		/// <summary>
+		/// Closes the Debug buffer
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Close ()
+		{
+			TraceImpl.Close ();
+		}
+
+		/// <summary>
+		/// Emits the specified error message.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Fail (string message)
+		{
+			TraceImpl.Fail (message);
+		}
+
+		/// <summary>
+		/// Emits the specified error message and detailed error message.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Fail (string message, string detailMessage)
+		{
+			TraceImpl.Fail (message, detailMessage);
+		}
+
+		/// <summary>
+		/// Flushes the listeners
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Flush ()
+		{
+			TraceImpl.Flush ();
+		}
+
+		/// <summary>
+		/// Increments the indent level
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Indent ()
+		{
+			TraceImpl.Indent ();
+		}
+
+		/// <summary>
+		/// Decrements the indent level
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Unindent ()
+		{
+			TraceImpl.Unindent ();
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method
+		/// to the listeners.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Write (object value)
+		{
+			TraceImpl.Write (value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each listener in the Listeners 
+		/// collection.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Write (string message)
+		{
+			TraceImpl.Write (message);
+		}
+
+		/// <summary>
+		/// Writes the category name and value of the specified object's
+		/// ToString method to each listener in the Listeners collection.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Write (object value, string category)
+		{
+			TraceImpl.Write (value, category);
+		}
+
+		/// <summary>
+		/// Writes the category name and the specified message
+		/// to each listener in the Listeners collection.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void Write (string message, string category)
+		{
+			TraceImpl.Write (message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method
+		/// to each of the listeners if the condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteIf (bool condition, object value)
+		{
+			TraceImpl.WriteIf (condition, value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each of the listeners
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteIf (bool condition, string message)
+		{
+			TraceImpl.WriteIf (condition, message);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString message
+		/// and category to each of the listeners if the condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteIf (bool condition, object value, 
+			string category)
+		{
+			TraceImpl.WriteIf (condition, value, category);
+		}
+
+		/// <summary>
+		/// Writes the category and specified message to each listener
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteIf (bool condition, string message, 
+			string category)
+		{
+			TraceImpl.WriteIf (condition, message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method,
+		/// followed by a line terminator, to each listener.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLine (object value)
+		{
+			TraceImpl.WriteLine (value);
+		}
+
+		/// <summary>
+		/// Writes the specified message, followed by a line terminator,
+		/// to each listener.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLine (string message)
+		{
+			TraceImpl.WriteLine (message);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method,
+		/// along with a category, followed by a line terminator, to each listener.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLine (object value, string category)
+		{
+			TraceImpl.WriteLine (value, category);
+		}
+
+		/// <summary>
+		/// Writes the specified category and message, followed by a line 
+		/// terminator, to each listener.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLine (string message, string category)
+		{
+			TraceImpl.WriteLine (message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method
+		/// to each listener if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLineIf (bool condition, object value)
+		{
+			TraceImpl.WriteLineIf (condition, value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each listener
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLineIf (bool condition, string message)
+		{
+			TraceImpl.WriteLineIf (condition, message);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method, and a category
+		/// to each listener if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLineIf (bool condition, object value, 
+			string category)
+		{
+			TraceImpl.WriteLineIf (condition, value, category);
+		}
+
+		/// <summary>
+		/// Writes the specified category and message to each listener, followed 
+		/// by a line terminator, if the specified condition is true.
+		/// </summary>
+		[Conditional("DEBUG")]
+		public static void WriteLineIf (bool condition, string message, 
+			string category)
+		{
+			TraceImpl.WriteLineIf (condition, message, category);
+		}
+	}
+}
+

+ 129 - 98
mcs/class/System/System.Diagnostics/DefaultTraceListener.cs

@@ -1,98 +1,129 @@
-//
-// System.Diagnostics.DefaultTraceListener.cs
-//
-// Author:
-//	John R. Hicks ([email protected])
-//
-// (C) 2001
-//
-using System;
-
-namespace System.Diagnostics
-{
-	/// <summary>
-	/// Provides the default output methods and behavior for tracing.
-	/// </summary>
-	/// <remarks>
-	/// Since there is no debugging API ala Win32 on Mono, <see cref="System.Console.Out">
-	/// Console.Out</see> is being used as the default output method.
-	/// </remarks>
-	public class DefaultTraceListener : TraceListener
-	{	
-		private string logFileName;
-		
-		public DefaultTraceListener() : base("Default")
-		{
-			logFileName = "";
-		}
-		
-		/// <summary>
-		/// Gets or sets name of a log file to write trace or debug messages to.
-		/// </summary>
-		/// <value>
-		/// The name of a log file to write trace or debug messages to.
-		/// </value>
-		public String LogFileName
-		{
-			get
-			{
-				return logFileName;
-			}
-			set
-			{
-				logFileName = value;
-			}
-		}
-		
-		/// <summary>
-		/// Emits or displays a message and a stack trace for an assertion that 
-		/// always fails.
-		/// </summary>
-		/// <param name="message">
-		/// The message to emit or display.
-		/// </param>
-		public override void Fail(string message)
-		{
-			Console.Out.WriteLine(message);
-			new StackTrace().ToString();
-		}
-		
-		/// <summary>
-		/// Emits or displays detailed messages and a stack trace
-		/// for an assertion that always fails.
-		/// </summary>
-		/// <param name="message">
-		/// The message to emit or display
-		/// </param>
-		/// <param name="detailMessage">
-		/// The detailed message to emit or display.
-		/// </param>
-		public override void Fail(string message, string detailMessage)
-		{
-			Console.Out.WriteLine(message + ": " + detailMessage);
-			new StackTrace().ToString();
-		}
-		
-		/// <summary>
-		/// Writes the output to the Console
-		/// </summary>
-		/// <param name="message">
-		/// The message to write
-		/// </param>
-		public override void Write(string message)
-		{
-			Console.Out.Write(message);
-		}
-		
-		/// <summary>
-		/// Writes the output to the Console, followed by a newline
-		/// </summary>
-		/// <param name="message">
-		/// The message to write
-		/// </param>
-		public override void WriteLine(string message)
-		{
-			Console.Out.WriteLine(message);
-		}
-	}
-}
+//
+// System.Diagnostics.DefaultTraceListener.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+ 	/// <summary>
+ 	/// Provides the default output methods and behavior for tracing.
+ 	/// </summary>
+ 	/// <remarks>
+ 	/// Since there is no debugging API ala Win32 on Mono, 
+  /// <see cref="System.Console.Out">
+ 	/// Console.Out</see> is being used as the default output method.
+	/// 
+  /// <para>This needs help, as MSDN specifies that GUI widgets be used 
+  /// for certain features.  The short-term solution is to just send output to
+  /// OutputDebugString.</para>
+ 	/// </remarks>
+	[ComVisible(false)]
+	public class DefaultTraceListener : TraceListener {
+
+		public DefaultTraceListener () : base ("Default")
+		{
+		}
+
+		[MonoTODO]
+		public bool AssertUiEnabled {
+			get {return false;}
+			set {/* ignore */}
+		}
+
+ 		/// <summary>
+ 		/// Gets or sets name of a log file to write trace or debug messages to.
+ 		/// </summary>
+ 		/// <value>
+ 		/// The name of a log file to write trace or debug messages to.
+ 		/// </value>
+		[MonoTODO]
+		public string LogFileName {
+			get {return "";}
+			set {/* ignore */}
+		}
+
+ 		/// <summary>
+ 		/// Emits or displays a message and a stack trace for an assertion that 
+ 		/// always fails.
+ 		/// </summary>
+ 		/// <param name="message">
+ 		/// The message to emit or display.
+ 		/// </param>
+    public override void Fail (string message)
+    {
+      base.Fail (message);
+      WriteLine (new StackTrace().ToString());
+    }
+
+ 		/// <summary>
+ 		/// Emits or displays detailed messages and a stack trace
+ 		/// for an assertion that always fails.
+ 		/// </summary>
+ 		/// <param name="message">
+ 		/// The message to emit or display
+ 		/// </param>
+ 		/// <param name="detailMessage">
+ 		/// The detailed message to emit or display.
+ 		/// </param>
+ 		public override void Fail(string message, string detailMessage)
+ 		{
+      base.Fail (message, detailMessage);
+      WriteLine (new StackTrace().ToString());
+ 		}
+
+		#if USE_NATIVE_WIN32_OUTPUT_DEBUG_STRING
+
+      [DllImport ("kernel32.dll")]
+      private extern static void OutputDebugString (string message);
+
+		#else
+
+      private static void OutputDebugString (string message)
+      {
+        Console.Write ("**ods** " + message);
+      }
+
+		#endif
+
+ 		/// <summary>
+ 		/// Writes the output to the Console
+ 		/// </summary>
+ 		/// <param name="message">
+ 		/// The message to write
+ 		/// </param>
+		public override void Write (string message)
+		{
+			if (NeedIndent)
+				WriteIndent ();
+			OutputDebugString (message);
+		}
+
+ 		/// <summary>
+ 		/// Writes the output to the Console, followed by a newline
+ 		/// </summary>
+ 		/// <param name="message">
+ 		/// The message to write
+ 		/// </param>
+		public override void WriteLine (string message)
+		{
+			if (NeedIndent)
+				WriteIndent ();
+			OutputDebugString (message + Environment.NewLine);
+			NeedIndent = true;
+		}
+	}
+}
+

+ 235 - 227
mcs/class/System/System.Diagnostics/TextWriterTraceListener.cs

@@ -1,227 +1,235 @@
-//
-// System.Diagnostics.TextWriterTraceListener.cs
-//
-// Author:
-//		John R. Hicks ([email protected])
-//
-// (C) 2001
-//
-namespace System.Diagnostics
-{
-	using System;
-	using System.IO;
-	using System.Text;
-	
-	/// <summary>
-	/// Directs tracing or debugging output to a <see cref="System.IO.TextWriter">
-	/// TextWriter</see> or to a <see cref="System.IO.Stream">Stream</see>,
-	/// such as <see cref="System.Console.Out">Console.Out</see> or
-	/// <see cref="System.IO.FileStream">FileStream</see>.
-	/// </summary>
-	public class TextWriterTraceListener : TraceListener
-	{	
-		
-		private TextWriter writer;
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class with <see cref="System.IO.TextWriter">
-		/// TextWriter</see> as the output recipient.
-		/// </summary>
-		public TextWriterTraceListener() : base("TextWriter")
-		{
-			writer = Console.Out;
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class, using the stream as the output
-		/// recipient of the debugging and tracing output.
-		/// </summary>
-		/// <param name="stream">
-		/// A <see cref="System.IO.Stream">Stream</see> that represents the stream the
-		/// <see cref="TextWriterTraceListener">TextWriterTraceListener</see> writes to.
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The stream is a null reference.
-		/// </exception>
-		public TextWriterTraceListener(Stream stream) : base("")
-		{
-			if(stream == null)
-				throw new ArgumentNullException("Stream is null");
-			
-			writer = new StreamWriter(stream);
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class, using the file as the recipient
-		/// of the debugging and tracing output.
-		/// </summary>
-		/// <param name="fileName">
-		/// The name of the file the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> writes to.
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The fileName is null.
-		/// </exception>
-		public TextWriterTraceListener(string fileName) : base("")
-		{
-			if(fileName == null)
-				throw new ArgumentNullException("Filename is null");
-			
-			FileStream fileStream = new FileStream(fileName, FileMode.Create);
-			writer = new StreamWriter(fileStream);
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class using the specified writer as the
-		/// recipient of the tracing or debugging output.
-		/// </summary>
-		/// <param name="writer">
-		/// A <see cref="System.IO.TextWriter">TextWriter</see> that receives output
-		/// from the <see cref="TextWriterTraceListener">TextWriterTraceListener</see>.
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The writer is a null reference
-		/// </exception>
-		public TextWriterTraceListener(TextWriter writer) : base("")
-		{
-			if(writer == null)
-				throw new ArgumentNullException("Given TextWriter is null");
-			this.writer = writer;
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class with the specified name, using the
-		/// stream as the recipient of the tracing or debugging output.
-		/// </summary>
-		/// <param name="stream">
-		/// A <see cref="System.IO.Stream">Stream</see> that represents the stream the
-		/// <see cref="TextWriterTraceListener">TextWriterTraceListener</see>
-		/// writes to.
-		/// </param>
-		/// <param name="name">
-		/// The name of the new instance
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The stream is a null reference
-		/// </exception>
-		public TextWriterTraceListener(Stream stream, string name) : base(name)
-		{
-			if(stream == null)
-				throw new ArgumentNullException("Supplied Stream is null");
-			writer = new StreamWriter(stream);
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class with the specified name, using the
-		/// file as the recipient of the tracing or debugging output.
-		/// </summary>
-		/// <param name="fileName">
-		/// The name of the file the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> writes to.
-		/// </param>
-		/// <param name="name">
-		/// The name of the new instance
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The file is a null reference.
-		/// </exception>
-		public TextWriterTraceListener(string fileName, string name) : base(name)
-		{
-			if(fileName == null)
-				throw new ArgumentNullException("Supplied file name is null");
-			FileStream fileStream = new FileStream(fileName, FileMode.Create);
-			writer = new StreamWriter(fileStream);
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
-		/// TextWriterTraceListener</see> class with the specified name, using
-		/// the specified writer as the recipient of the tracing or debugging output.
-		/// </summary>
-		/// <param name="writer">
-		/// A <see cref="System.IO.TextWriter">TextWriter</see> that receives the output
-		/// from the <see cref="TextWriterTraceListener">TextWriterTraceListener</see>.
-		/// </param>
-		/// <param name="name">
-		/// The name of the new instance.
-		/// </param>
-		/// <exception cref="System.ArgumentNullException">
-		/// The writer is a null reference.
-		/// </exception>
-		public TextWriterTraceListener(TextWriter writer, string name) : base(name)
-		{
-			if(writer == null)
-				throw new ArgumentNullException("The supplied writer is null");
-			this.writer = writer;
-		}
-		
-		/// <summary>
-		/// Gets or sets the writer that receives the debugging or tracing output.
-		/// </summary>
-		/// <value>
-		/// A <see cref="System.IO.TextWriter">TextWriter</see> that represents the writer
-		/// that receives the tracing or debugging output.
-		/// </value>
-		public TextWriter Writer
-		{
-			get
-			{
-				return writer;
-			}
-			set
-			{
-				writer = value;
-			}
-		}
-		
-		/// <summary>
-		/// Closes the <see cref="System.IO.Writer">Writer</see> so that it no longer
-		/// receives tracing or debugging output.
-		/// </summary>
-		public override void Close()
-		{
-			writer.Close();
-		}
-		
-		/// <summary>
-		/// Flushes the output buffer for the <see cref="System.IO.Writer">Writer</see>.
-		/// </summary>
-		public override void Flush()
-		{
-			writer.Flush();
-		}
-		
-		/// <summary>
-		/// Writes a message to this instance's <see cref="System.IO.Writer">Writer</see>.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		public override void Write(string message)
-		{
-			Console.Error.WriteLine("We should be getting output here");
-			writer.Write(message);
-			
-		}
-		
-		/// <summary>
-		/// Writes a message to this instance's <see cref="System.IO.Writer">Writer</see>
-		/// followed by a line terminator.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		public override void WriteLine(string message)
-		{
-			Console.Error.WriteLine("We should be getting output here, too");	
-			writer.WriteLine(message);
-			
-		}
-	}
-}
+//
+// System.Diagnostics.TextWriterTraceListener.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+using System.IO;
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+	/// <summary>
+	/// Directs tracing or debugging output to a <see cref="System.IO.TextWriter">
+	/// TextWriter</see> or to a <see cref="System.IO.Stream">Stream</see>,
+	/// such as <see cref="System.Console.Out">Console.Out</see> or
+	/// <see cref="System.IO.FileStream">FileStream</see>.
+	/// </summary>
+	public class TextWriterTraceListener : TraceListener {
+
+		private TextWriter writer;
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class with 
+		/// <see cref="System.IO.TextWriter">TextWriter</see> 
+		/// as the output recipient.
+		/// </summary>
+		public TextWriterTraceListener () : base ("TextWriter")
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class, using the stream as the output
+		/// recipient of the debugging and tracing output.
+		/// </summary>
+		/// <param name="stream">
+		/// A <see cref="System.IO.Stream">Stream</see> that represents the stream 
+		/// the <see cref="TextWriterTraceListener">TextWriterTraceListener</see> 
+		/// writes to.
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The stream is a null reference.
+		/// </exception>
+		public TextWriterTraceListener (Stream stream)
+			: this (stream, "")
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class, using the file as the recipient
+		/// of the debugging and tracing output.
+		/// </summary>
+		/// <param name="fileName">
+		/// The name of the file the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> writes to.
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The fileName is null.
+		/// </exception>
+		public TextWriterTraceListener (string fileName)
+			: this (fileName, "")
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class using the specified writer as the
+		/// recipient of the tracing or debugging output.
+		/// </summary>
+		/// <param name="writer">
+		/// A <see cref="System.IO.TextWriter">TextWriter</see> that receives 
+		/// output from the 
+		/// <see cref="TextWriterTraceListener">TextWriterTraceListener</see>.
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The writer is a null reference
+		/// </exception>
+		public TextWriterTraceListener (TextWriter writer)
+			: this (writer, "")
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class with the specified name, using the
+		/// stream as the recipient of the tracing or debugging output.
+		/// </summary>
+		/// <param name="stream">
+		/// A <see cref="System.IO.Stream">Stream</see> that represents the stream 
+		/// the <see cref="TextWriterTraceListener">TextWriterTraceListener</see>
+		/// writes to.
+		/// </param>
+		/// <param name="name">
+		/// The name of the new instance
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The stream is a null reference
+		/// </exception>
+		public TextWriterTraceListener (Stream stream, string name) 
+			: base (name != null ? name : "")
+		{
+			if (stream == null) 
+				throw new ArgumentNullException ("stream");
+			writer = new StreamWriter (stream);
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class with the specified name, using the
+		/// file as the recipient of the tracing or debugging output.
+		/// </summary>
+		/// <param name="fileName">
+		/// The name of the file the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> writes to.
+		/// </param>
+		/// <param name="name">
+		/// The name of the new instance
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The file is a null reference.
+		/// </exception>
+		public TextWriterTraceListener (string fileName, string name) 
+			: base (name != null ? name : "")
+		{
+			if (fileName == null)
+				throw new ArgumentNullException ("fileName");
+			writer = new StreamWriter (File.OpenWrite (fileName));
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TextWriterTraceListener">
+		/// TextWriterTraceListener</see> class with the specified name, using
+		/// the specified writer as the recipient of the tracing or 
+		/// debugging output.
+		/// </summary>
+		/// <param name="writer">
+		/// A <see cref="System.IO.TextWriter">TextWriter</see> that receives 
+		/// the output from the 
+		/// <see cref="TextWriterTraceListener">TextWriterTraceListener</see>.
+		/// </param>
+		/// <param name="name">
+		/// The name of the new instance.
+		/// </param>
+		/// <exception cref="System.ArgumentNullException">
+		/// The writer is a null reference.
+		/// </exception>
+		public TextWriterTraceListener (TextWriter writer, string name) 
+			: base (name != null ? name : "")
+		{
+			if (writer == null)
+				throw new ArgumentNullException ("writer");
+			this.writer = writer;
+		}
+
+		/// <summary>
+		/// Gets or sets the writer that receives the debugging or tracing output.
+		/// </summary>
+		/// <value>
+		/// A <see cref="System.IO.TextWriter">TextWriter</see> that represents 
+		/// the writer that receives the tracing or debugging output.
+		/// </value>
+		public TextWriter Writer {
+			get {return writer;}
+			set {writer = value;}
+		}
+
+		/// <summary>
+		/// Closes the <see cref="System.IO.Writer">Writer</see> so that it no 
+		/// longer receives tracing or debugging output.
+		/// </summary>
+		public override void Close ()
+		{
+			if (writer != null) {
+				writer.Flush ();
+				writer.Close ();
+				writer = null;
+			}
+		}
+
+		protected override void Dispose (bool disposing)
+		{
+			if (disposing)
+				Close ();
+		}
+
+		/// <summary>
+		/// Flushes the output buffer for the 
+		/// <see cref="System.IO.Writer">Writer</see>.
+		/// </summary>
+		public override void Flush ()
+		{
+			writer.Flush ();
+		}
+
+		/// <summary>
+		/// Writes a message to this instance's 
+		/// <see cref="System.IO.Writer">Writer</see>.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		public override void Write (string message)
+		{
+			if (NeedIndent)
+				WriteIndent ();
+			writer.Write (message);
+		}
+
+		/// <summary>
+		/// Writes a message to this instance's 
+		/// <see cref="System.IO.Writer">Writer</see>
+		/// followed by a line terminator.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		public override void WriteLine (string message)
+		{
+			if (NeedIndent)
+				WriteIndent ();
+			writer.WriteLine (message);
+			NeedIndent = true;
+		}
+	}
+}
+

+ 305 - 0
mcs/class/System/System.Diagnostics/Trace.cs

@@ -0,0 +1,305 @@
+//
+// System.Diagnostics.Trace.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002
+//
+
+using System;
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+	/// <summary>
+	/// Provides a set of methods to help debug code
+	/// </summary>
+	public sealed class Trace {
+
+		/// <summary>
+		/// Gets or sets value indicating whether Flush should
+		/// be called on the listeners.
+		/// </summary>
+		public static bool AutoFlush {
+			get {return TraceImpl.AutoFlush;}
+			set {TraceImpl.AutoFlush = value;}
+		}
+
+		/// <summary>
+		/// Gets or sets indent level
+		/// </summary>
+		public static int IndentLevel {
+			get {return TraceImpl.IndentLevel;}
+			set {TraceImpl.IndentLevel = value;}
+		}
+
+		/// <summary>
+		/// The number of spaces in an indent.
+		/// </summary>
+		public static int IndentSize {
+			get {return TraceImpl.IndentSize;}
+			set {TraceImpl.IndentSize = value;}
+		}
+
+		/// <summary>
+		/// Returns the listeners collection
+		/// </summary>
+		public static TraceListenerCollection Listeners {
+			get {return TraceImpl.Listeners;}
+		}
+
+		/// <summary>
+		/// Checks for a condition, and prints a stack trace
+		/// if the condition is false.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Assert (bool condition)
+		{
+			TraceImpl.Assert (condition);
+		}
+
+		/// <summary>
+		/// Checks for a condition, and displays a message if the condition
+		/// is false.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Assert (bool condition, string message)
+		{
+			TraceImpl.Assert (condition, message);
+		}
+
+		/// <summary>
+		/// Checks for a condtion, and displays a message and a detailed message
+		/// string if the condition is false.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Assert (bool condition, string message, 
+			string detailMessage)
+		{
+			TraceImpl.Assert (condition, message, detailMessage);
+		}
+
+		/// <summary>
+		/// Closes the Debug buffer
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Close ()
+		{
+			TraceImpl.Close ();
+		}
+
+		/// <summary>
+		/// Emits the specified error message.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Fail (string message)
+		{
+			TraceImpl.Fail (message);
+		}
+
+		/// <summary>
+		/// Emits the specified error message and detailed error message.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Fail (string message, string detailMessage)
+		{
+			TraceImpl.Fail (message, detailMessage);
+		}
+
+		/// <summary>
+		/// Flushes the listeners
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Flush ()
+		{
+			TraceImpl.Flush ();
+		}
+
+		/// <summary>
+		/// Increments the indent level
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Indent ()
+		{
+			TraceImpl.Indent ();
+		}
+
+		/// <summary>
+		/// Decrements the indent level
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Unindent ()
+		{
+			TraceImpl.Unindent ();
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method
+		/// to the listeners.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Write (object value)
+		{
+			TraceImpl.Write (value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each listener in the Listeners 
+		/// collection.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Write (string message)
+		{
+			TraceImpl.Write (message);
+		}
+
+		/// <summary>
+		/// Writes the category name and value of the specified object's
+		/// ToString method to each listener in the Listeners collection.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Write (object value, string category)
+		{
+			TraceImpl.Write (value, category);
+		}
+
+		/// <summary>
+		/// Writes the category name and the specified message
+		/// to each listener in the Listeners collection.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void Write (string message, string category)
+		{
+			TraceImpl.Write (message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method
+		/// to each of the listeners if the condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteIf (bool condition, object value)
+		{
+			TraceImpl.WriteIf (condition, value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each of the listeners
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteIf (bool condition, string message)
+		{
+			TraceImpl.WriteIf (condition, message);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString message
+		/// and category to each of the listeners if the condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteIf (bool condition, object value, 
+			string category)
+		{
+			TraceImpl.WriteIf (condition, value, category);
+		}
+
+		/// <summary>
+		/// Writes the category and specified message to each listener
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteIf (bool condition, string message, 
+			string category)
+		{
+			TraceImpl.WriteIf (condition, message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method,
+		/// followed by a line terminator, to each listener.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLine (object value)
+		{
+			TraceImpl.WriteLine (value);
+		}
+
+		/// <summary>
+		/// Writes the specified message, followed by a line terminator,
+		/// to each listener.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLine (string message)
+		{
+			TraceImpl.WriteLine (message);
+		}
+
+		/// <summary>
+		/// Writes the value of the specified object's ToString method,
+		/// along with a category, followed by a line terminator, to each listener.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLine (object value, string category)
+		{
+			TraceImpl.WriteLine (value, category);
+		}
+
+		/// <summary>
+		/// Writes the specified category and message, followed by a line 
+		/// terminator, to each listener.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLine (string message, string category)
+		{
+			TraceImpl.WriteLine (message, category);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method
+		/// to each listener if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLineIf (bool condition, object value)
+		{
+			TraceImpl.WriteLineIf (condition, value);
+		}
+
+		/// <summary>
+		/// Writes the specified message to each listener
+		/// if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLineIf (bool condition, string message)
+		{
+			TraceImpl.WriteLineIf (condition, message);
+		}
+
+		/// <summary>
+		/// Writes the value of the object's ToString method, and a category
+		/// to each listener if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLineIf (bool condition, object value, 
+			string category)
+		{
+			TraceImpl.WriteLineIf (condition, value, category);
+		}
+
+		/// <summary>
+		/// Writes the specified category and message to each listener, followed 
+		/// by a line terminator, if the specified condition is true.
+		/// </summary>
+		[Conditional("TRACE")]
+		public static void WriteLineIf (bool condition, string message, 
+			string category)
+		{
+			TraceImpl.WriteLineIf (condition, message, category);
+		}
+	}
+}
+

+ 296 - 0
mcs/class/System/System.Diagnostics/TraceImpl.cs

@@ -0,0 +1,296 @@
+//
+// System.Diagnostics.TraceImpl.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// (C) 2002 Jonathan Pryor
+//
+
+
+using System;
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+	internal class TraceImpl {
+
+		private static object lock_ = new object ();
+
+		private static bool autoFlush = false;
+
+		public static bool AutoFlush {
+			get {return autoFlush;}
+			set {autoFlush = value;}
+		}
+
+		// FIXME: From MSDN: "This property is stored on 
+		// per-thread/pre-reqeust basis"
+		//
+		// What exactly does this mean?  Sure, we can mark it
+		// [ThreadStatic], which make a per-thread value, but what
+		// does this mean for each of the writers?  Do *they* need to
+		// store this as a thread-static value?
+		[MonoTODO, ThreadStatic]
+		private static int indentLevel = 0;
+
+		public static int IndentLevel {
+			get {return indentLevel;}
+			set {indentLevel = value;}
+		}
+
+		// FIXME: From MSDN: "This property is stored on 
+		// per-thread/pre-reqeust basis"
+		//
+		// What exactly does this mean?  Sure, we can mark it
+		// [ThreadStatic], which makes a per-thread value, but what
+		// does this mean for each of the writers?  Do *they* need to
+		// store this as a thread-static value?
+		[MonoTODO, ThreadStatic]
+		private static int indentSize = 4;
+
+		public static int IndentSize {
+			get {return indentSize;}
+			set {indentSize = value;}
+		}
+
+		private static TraceListenerCollection listeners = 
+			new TraceListenerCollection ();
+
+		public static TraceListenerCollection Listeners {
+			get {return listeners;}
+		}
+
+		// FIXME: According to MSDN, this method should display a dialog box
+		[MonoTODO]
+		public static void Assert (bool condition)
+		{
+			if (!condition)
+				Fail (new StackTrace().ToString());
+		}
+
+		// FIXME: According to MSDN, this method should display a dialog box
+		[MonoTODO]
+		public static void Assert (bool condition, string message)
+		{
+			if (!condition)
+				Fail (message);
+		}
+
+		// FIXME: According to MSDN, this method should display a dialog box
+		[MonoTODO]
+		public static void Assert (bool condition, string message, 
+			string detailMessage)
+		{
+			if (!condition)
+				Fail (message, detailMessage);
+		}
+
+		public static void Close ()
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Close ();
+				}
+			}
+		}
+
+		// FIXME: From testing .NET, this method should display a dialog
+		[MonoTODO]
+		public static void Fail (string message)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Fail (message);
+				}
+			}
+		}
+
+		// FIXME: From testing .NET, this method should display a dialog
+		[MonoTODO]
+		public static void Fail (string message, string detailMessage)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Fail (message, detailMessage);
+				}
+			}
+		}
+
+		public static void Flush ()
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners){
+					listener.Flush ();
+				}
+			}
+		}
+
+		public static void Indent ()
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.IndentLevel++;
+				}
+			}
+		}
+
+		public static void Unindent ()
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.IndentLevel--;
+				}
+			}
+		}
+
+		public static void Write (object value)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Write (value);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void Write (string message)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Write (message);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void Write (object value, string category)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Write (value, category);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void Write (string message, string category)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.Write (message, category);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void WriteIf (bool condition, object value)
+		{
+			if (condition)
+				Write (value);
+		}
+
+		public static void WriteIf (bool condition, string message)
+		{
+			if (condition)
+				Write (message);
+		}
+
+		public static void WriteIf (bool condition, object value, 
+			string category)
+		{
+			if (condition)
+				Write (value, category);
+		}
+
+		public static void WriteIf (bool condition, string message, 
+			string category)
+		{
+			if (condition)
+				Write (message, category);
+		}
+
+		public static void WriteLine (object value)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.WriteLine (value);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void WriteLine (string message)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.WriteLine (message);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void WriteLine (object value, string category)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.WriteLine (value, category);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void WriteLine (string message, string category)
+		{
+			lock (lock_) {
+				foreach (TraceListener listener in Listeners) {
+					listener.WriteLine (message, category);
+
+					if (AutoFlush)
+						listener.Flush ();
+				}
+			}
+		}
+
+		public static void WriteLineIf (bool condition, object value)
+		{
+			if (condition)
+				WriteLine (value);
+		}
+
+		public static void WriteLineIf (bool condition, string message)
+		{
+			if (condition)
+				WriteLine (message);
+		}
+
+		public static void WriteLineIf (bool condition, object value, 
+			string category)
+		{
+			if (condition)
+				WriteLine (value, category);
+		}
+
+		public static void WriteLineIf (bool condition, string message, 
+			string category)
+		{
+			if (condition)
+				WriteLine (message, category);
+		}
+	}
+}
+

+ 295 - 300
mcs/class/System/System.Diagnostics/TraceListener.cs

@@ -1,300 +1,295 @@
-//
-// System.Diagnostics.TraceListener.cs
-//
-// Author:
-//		John R. Hicks ([email protected])
-//
-// (C) 2001
-//
-namespace System.Diagnostics
-{
-	using System;
-	using System.IO;
-	using System.Text;
-	
-	/// <summary>
-	/// Provides the abstract base class for the listeners who monitor
-	/// trace and debug output
-	/// </summary>
-	public abstract class TraceListener : MarshalByRefObject, IDisposable
-	{
-		private int indentLevel;
-		private int indentSize;
-		private string name;
-		private bool needIndent;
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TraceListener">
-		/// TraceListener</see> class.
-		/// </summary>
-		protected TraceListener()
-		{
-			indentLevel = 0;
-			indentSize = 4;
-			needIndent = false;
-			name = "";
-		}
-		
-		/// <summary>
-		/// Initializes a new instance of the <see cref="TraceListener">
-		/// TraceListener</see> class using the specified name as the listener.
-		/// </summary>
-		protected TraceListener(string name) : this()
-		{
-			if(name == null)
-				this.name = "";
-			this.name = name;
-		}
-		
-		/// <summary>
-		/// Gets or sets the indent level.
-		/// </summary>
-		/// <value>
-		/// The indent level.  The default is zero.
-		/// </value>
-		public int IndentLevel
-		{
-			get
-			{
-				return indentLevel;
-			}
-			set
-			{
-				indentLevel = value;
-			}
-		}
-		
-		/// <summary>
-		/// Gets or sets the number of spaces in an indent.
-		/// </summary>
-		/// <value>
-		/// The number of spaces in an indent.  The default is four spaces.
-		/// </value>
-		public int IndentSize
-		{
-			get
-			{
-				return indentSize;
-			}
-			set
-			{
-				indentSize = value;
-			}
-		}
-		
-		/// <summary>
-		/// Gets or sets a name for this <see cref="TraceListener">TraceListener</see>.
-		/// </summary>
-		/// <value>
-		/// A name for this <see cref="TraceListener">TraceListener</see>.
-		/// The default is the empty string ("")
-		/// </value>
-		public string Name
-		{
-			get
-			{
-				return name;
-			}
-			set
-			{
-				name = value;
-			}
-		}
-		
-		/// <summary>
-		/// Gets or sets a value indicating whether to indent the output.
-		/// </summary>
-		/// <value>
-		/// <b>true</b> if the output should be indented; otherwise <b>false</b>.
-		/// </value>
-		protected bool NeedIndent
-		{
-			get
-			{
-				return needIndent;
-			}
-			set
-			{
-				needIndent = value;
-			}
-		}
-		
-		/// <summary>
-		/// When overridden in a derived class, closes the output stream so it no longer
-		/// receives tracing or debugging output.
-		/// </summary>
-		public virtual void Close() {}
-		
-		/// <summary>
-		/// Releases all resources used by the <see cref="TraceListener">TraceListener</see>.
-		/// </summary>
-		public virtual void Dispose() {}
-		
-		/// <summary>
-		/// Releases the unmanaged resources used by the 
-		/// <see cref="TraceListener">TraceListener</see> and optionally releases the
-		/// managed resources.
-		/// </summary>
-		/// <param name="disposing">
-		/// <b>true</b> to release both managed and unmanaged resources;
-		/// <b>false</b> to release only unmanaged resources.
-		/// </param>
-		protected virtual void Dispose(bool disposing) {}
-		
-		/// <summary>
-		/// Emits an error message to the listener you create when you 
-		/// implement the <see cref="TraceListener">TraceListener</see> class.
-		/// </summary>
-		/// <param name="message">
-		/// A message to emit.
-		/// </param>
-		public virtual void Fail(string message)
-		{
-			
-		}
-		
-		/// <summary>
-		/// Emits an error message, and a detailed error message to the listener
-		/// you create when you implement the <see cref="TraceListener">TraceListener</see>
-		/// class.
-		/// </summary>
-		/// <param name="message">
-		/// A message to emit.
-		/// </param>
-		/// <param name="detailMessage">
-		/// A detailed message to emit.
-		/// </param>
-		public virtual void Fail(string message, string detailMessage)
-		{
-			
-		}
-		
-		/// <summary>
-		/// When overridden in a derived class, flushes the output buffer.
-		/// </summary>
-		public virtual void Flush() {}
-		
-		/// <summary>
-		/// Writes the value of the object's <see cref="System.Object.ToString">ToString</see>
-		/// method to the listener you create when you implement the
-		/// <see cref="TraceListener">TraceListener</see> class.
-		/// </summary>
-		/// <param name="o">
-		/// An <see cref="System.Object">Object</see> whose fully qualified
-		/// class name you want to write.
-		/// </param>
-		public virtual void Write(object o) 
-		{
-			
-		}
-		
-		/// <summary>
-		/// When overridden in a derived class, writes the specified message to 
-		/// the listener you create in the derived class.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		public abstract void Write(string message);
-		
-		/// <summary>
-		/// Writes a category name and the value of the object's 
-		/// <see cref="System.Object.ToString">ToString</see>
-		/// method to the listener you create when you implement the
-		/// <see cref="TraceListener">TraceListener</see> class.
-		/// </summary>
-		/// <param name="o">
-		/// An <see cref="System.Object">Object</see> whose fully qualified
-		/// class name you wish to write.
-		/// </param>
-		/// <param name="category">
-		/// A category name used to organize the output.
-		/// </param>
-		public virtual void Write(object o, string category)
-		{
-			
-		}
-		
-		/// <summary>
-		/// Writes a category name and a message to the listener you create when 
-		/// you implement the <see cref="TraceListener">TraceListener</see> class.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		/// <param name="category">
-		/// A category name used to organize the output.
-		/// </param>
-		public virtual void Write(string message, string category)
-		{
-			
-		}
-		
-		/// <summary>
-		/// Writes the value of the object's <see cref="System.Object.ToString">ToString</see>
-		/// method to the listener you create when you implement the
-		/// <see cref="TraceListener">TraceListener</see> class, followed by a line terminator.
-		/// </summary>
-		/// <param name="o">
-		/// An <see cref="System.Object">Object</see> whose fully qualified
-		/// class name you want to write.
-		/// </param>
-		public virtual void WriteLine(object o) 
-		{
-			
-		}
-		
-		/// <summary>
-		/// When overridden in a derived class, writes the specified message to 
-		/// the listener you create in the derived class, followed by a line terminator.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		public abstract void WriteLine(string message);
-		
-		/// <summary>
-		/// Writes a category name and the value of the object's 
-		/// <see cref="System.Object.ToString">ToString</see>
-		/// method to the listener you create when you implement the
-		/// <see cref="TraceListener">TraceListener</see> class, followed by a
-		/// line terminator.
-		/// </summary>
-		/// <param name="o">
-		/// An <see cref="System.Object">Object</see> whose fully qualified
-		/// class name you wish to write.
-		/// </param>
-		/// <param name="category">
-		/// A category name used to organize the output.
-		/// </param>
-		public virtual void WriteLine(object o, string category)
-		{
-			
-		}
-		
-		/// <summary>
-		/// Writes a category name and a message to the listener you create when 
-		/// you implement the <see cref="TraceListener">TraceListener</see> class,
-		/// followed by a line terminator.
-		/// </summary>
-		/// <param name="message">
-		/// A message to write.
-		/// </param>
-		/// <param name="category">
-		/// A category name used to organize the output.
-		/// </param>
-		public virtual void WriteLine(string message, string category)
-		{
-			
-		}
-		
-		/// <summary>
-		/// Writes the indent to the listener you create when you implement this class,
-		/// and resets the <see cref="NeedIndent">NeedIndent</see> Property to <b>false</b>.
-		/// </summary>
-		protected virtual void WriteIndent()
-		{
-			
-		}
-	}
-}
+//
+// System.Diagnostics.TraceListener.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+using System.Diagnostics;
+
+namespace System.Diagnostics {
+
+	/// <summary>
+	/// Provides the abstract base class for the listeners who monitor
+	/// trace and debug output
+	/// </summary>
+	public abstract class TraceListener : MarshalByRefObject, IDisposable {
+
+		private int indentLevel = 0;
+		private int indentSize = 4;
+		private string name = null;
+		private bool needIndent = false;
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TraceListener">
+		/// TraceListener</see> class.
+		/// </summary>
+		protected TraceListener () : this ("")
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="TraceListener">
+		/// TraceListener</see> class using the specified name as the listener.
+		/// </summary>
+		protected TraceListener (string name)
+		{
+			Name = name;
+		}
+
+		/// <summary>
+		/// Gets or sets the indent level.
+		/// </summary>
+		/// <value>
+		/// The indent level.  The default is zero.
+		/// </value>
+		public int IndentLevel {
+			get {return indentLevel;}
+			set {indentLevel = value;}
+		}
+
+		/// <summary>
+		/// Gets or sets the number of spaces in an indent.
+		/// </summary>
+		/// <value>
+		/// The number of spaces in an indent.  The default is four spaces.
+		/// </value>
+		public int IndentSize {
+			get {return indentSize;}
+			set {indentSize = value;}
+		}
+
+		/// <summary>
+		/// Gets or sets a name for this 
+		/// <see cref="TraceListener">TraceListener</see>.
+		/// </summary>
+		/// <value>
+		/// A name for this <see cref="TraceListener">TraceListener</see>.
+		/// The default is the empty string ("")
+		/// </value>
+		public virtual string Name {
+			get {return name;}
+			set {name = value;}
+		}
+
+		/// <summary>
+		/// Gets or sets a value indicating whether to indent the output.
+		/// </summary>
+		/// <value>
+		/// <b>true</b> if the output should be indented; otherwise <b>false</b>.
+		/// </value>
+		protected bool NeedIndent {
+			get {return needIndent;}
+			set {needIndent = value;}
+		}
+
+		/// <summary>
+		/// When overridden in a derived class, closes the output stream so it 
+		/// no longer receives tracing or debugging output.
+		/// </summary>
+		public virtual void Close ()
+		{
+			Dispose ();
+		}
+
+		/// <summary>
+		/// Releases all resources used by the i
+		/// <see cref="TraceListener">TraceListener</see>.
+		/// </summary>
+		public void Dispose ()
+		{
+			Dispose (true);
+			GC.SuppressFinalize (this);
+		}
+
+		/// <summary>
+		/// Releases the unmanaged resources used by the 
+		/// <see cref="TraceListener">TraceListener</see> and optionally 
+		/// releases the managed resources.
+		/// </summary>
+		/// <param name="disposing">
+		/// <b>true</b> to release both managed and unmanaged resources;
+		/// <b>false</b> to release only unmanaged resources.
+		/// </param>
+		protected virtual void Dispose (bool disposing)
+		{
+		}
+
+		/// <summary>
+		/// Emits an error message to the listener you create when you 
+		/// implement the <see cref="TraceListener">TraceListener</see> class.
+		/// </summary>
+		/// <param name="message">
+		/// A message to emit.
+		/// </param>
+		public virtual void Fail (string message)
+		{
+			Fail (message, "");
+		}
+
+		/// <summary>
+		/// Emits an error message, and a detailed error message to the listener
+		/// you create when you implement the 
+		/// <see cref="TraceListener">TraceListener</see> class.
+		/// </summary>
+		/// <param name="message">
+		/// A message to emit.
+		/// </param>
+		/// <param name="detailMessage">
+		/// A detailed message to emit.
+		/// </param>
+		public virtual void Fail (string message, string detailMessage)
+		{
+			WriteLine ("---- DEBUG ASSERTION FAILED ----");
+			WriteLine ("---- Assert Short Message ----");
+			WriteLine (message);
+			WriteLine ("---- Assert Long Message ----");
+			WriteLine (detailMessage);
+			WriteLine ("");
+		}
+
+		/// <summary>
+		/// When overridden in a derived class, flushes the output buffer.
+		/// </summary>
+		public virtual void Flush ()
+		{
+		}
+
+		/// <summary>
+		/// Writes the value of the object's 
+		/// <see cref="System.Object.ToString">ToString</see>
+		/// method to the listener you create when you implement the
+		/// <see cref="TraceListener">TraceListener</see> class.
+		/// </summary>
+		/// <param name="o">
+		/// An <see cref="System.Object">Object</see> whose fully qualified
+		/// class name you want to write.
+		/// </param>
+		public virtual void Write (object o)
+		{
+			Write (o.ToString());
+		}
+
+		/// <summary>
+		/// When overridden in a derived class, writes the specified message to 
+		/// the listener you create in the derived class.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		public abstract void Write (string message);
+
+		/// <summary>
+		/// Writes a category name and the value of the object's 
+		/// <see cref="System.Object.ToString">ToString</see>
+		/// method to the listener you create when you implement the
+		/// <see cref="TraceListener">TraceListener</see> class.
+		/// </summary>
+		/// <param name="o">
+		/// An <see cref="System.Object">Object</see> whose fully qualified
+		/// class name you wish to write.
+		/// </param>
+		/// <param name="category">
+		/// A category name used to organize the output.
+		/// </param>
+		public virtual void Write (object o, string category)
+		{
+			Write (o.ToString(), category);
+		}
+
+		/// <summary>
+		/// Writes a category name and a message to the listener you create when 
+		/// you implement the <see cref="TraceListener">TraceListener</see> class.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		/// <param name="category">
+		/// A category name used to organize the output.
+		/// </param>
+		public virtual void Write (string message, string category)
+		{
+			Write (category + ": " + message);
+		}
+
+		/// <summary>
+		/// Writes the indent to the listener you create when you implement 
+		/// this class, and resets the <see cref="NeedIndent">NeedIndent</see> 
+		/// Property to <b>false</b>.
+		/// </summary>
+		protected virtual void WriteIndent ()
+		{
+			String indent = new String (' ', IndentLevel*IndentSize);
+			Write (indent);
+			NeedIndent = false;
+		}
+
+		/// <summary>
+		/// Writes the value of the object's 
+		/// <see cref="System.Object.ToString">ToString</see>
+		/// method to the listener you create when you implement the
+		/// <see cref="TraceListener">TraceListener</see> class, followed 
+		/// by a line terminator.
+		/// </summary>
+		/// <param name="o">
+		/// An <see cref="System.Object">Object</see> whose fully qualified
+		/// class name you want to write.
+		/// </param>
+		public virtual void WriteLine (object o)
+		{
+			WriteLine (o.ToString());
+		}
+
+		/// <summary>
+		/// When overridden in a derived class, writes the specified message to 
+		/// the listener you create in the derived class, followed by a 
+		/// line terminator.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		public abstract void WriteLine (string message);
+
+		/// <summary>
+		/// Writes a category name and the value of the object's 
+		/// <see cref="System.Object.ToString">ToString</see>
+		/// method to the listener you create when you implement the
+		/// <see cref="TraceListener">TraceListener</see> class, followed by a
+		/// line terminator.
+		/// </summary>
+		/// <param name="o">
+		/// An <see cref="System.Object">Object</see> whose fully qualified
+		/// class name you wish to write.
+		/// </param>
+		/// <param name="category">
+		/// A category name used to organize the output.
+		/// </param>
+		public virtual void WriteLine (object o, string category)
+		{
+			WriteLine (o.ToString(), category);
+		}
+
+		/// <summary>
+		/// Writes a category name and a message to the listener you create when 
+		/// you implement the <see cref="TraceListener">TraceListener</see> class,
+		/// followed by a line terminator.
+		/// </summary>
+		/// <param name="message">
+		/// A message to write.
+		/// </param>
+		/// <param name="category">
+		/// A category name used to organize the output.
+		/// </param>
+		public virtual void WriteLine (string message, string category)
+		{
+			WriteLine (category + ": " + message);
+		}
+	}
+}
+

+ 281 - 290
mcs/class/System/System.Diagnostics/TraceListenerCollection.cs

@@ -1,290 +1,281 @@
-//
-// System.Diagnostics.TraceListenerCollection.cs
-//
-// Author: John R. Hicks <[email protected]>
-//
-// (C) 2001
-//
-using System;
-using System.Collections;
-
-namespace System.Diagnostics
-{
-	
-	/// <summary>
-	/// Provides a list of TraceListener objects.
-	/// </summary>
-	public class TraceListenerCollection : IList, ICollection,
-		IEnumerable
-	{
-		private int count;
-		private bool isReadOnly;
-		private bool isFixedSize;
-		private bool isSynchronized;
-		private ArrayList listeners;
-		
-		/// <summary>
-		/// Gets the first TraceListener in the list with the
-		/// specified name.
-		/// </summary>
-		public TraceListener this[string name]
-		{
-			get
-			{
-				int index = listeners.IndexOf(name);
-				return (TraceListener)listeners[index];
-			}
-		}
-		
-		public object this[int index]
-		{
-			get
-			{
-				return listeners[index];
-			}
-			set
-			{
-				listeners[index] = value;
-			}
-		}
-		
-		internal TraceListenerCollection()
-		{
-			count = 0;
-			isReadOnly = false;
-			isFixedSize = false;
-			isSynchronized = false;
-			listeners = new ArrayList();
-			listeners.Add(new DefaultTraceListener());
-		}
-		
-		/// <summary>
-		/// Returns the number of items in the list
-		/// </summary>
-		/// <value>
-		/// The number of items
-		/// </value>
-		public int Count
-		{
-			get
-			{
-				return count;
-			}
-			set
-			{
-				count = value;
-			}
-		}
-		
-		/// <summary>
-		/// Adds a TraceListener to the list.
-		/// </summary>
-		/// <param name="listener">
-		/// The TraceListener being added to the list.
-		/// </param>
-		/// <return>
-		/// The position in the list where the listener was inserted.
-		/// </return>
-		public int Add(object listener)
-		{
-			return listeners.Add(listener);
-		}
-		
-		/// <summary>
-		/// Adds an array of TraceListeners to the list.
-		/// </summary>
-		/// <param name="value">
-		/// Array of TraceListeners to add
-		/// </param>
-		public void AddRange(TraceListener[] value)
-		{
-			listeners.AddRange(value);
-		}
-		
-		/// <summary>
-		/// Adds the contents of another TraceListenerCollection to this one.
-		/// </summary>
-		/// <param name="value">
-		/// The TraceListenerCollection to copy values from.
-		/// </param>
-		[MonoTODO]
-		public void AddRange(TraceListenerCollection value)
-		{
-			// TODO: use an iterator to copy the objects.
-			for(int i = 0; i < value.count; i++)
-			{
-				listeners.Add(value[i]);
-			}
-		}
-		
-		/// <summary>
-		/// Clears all listeners from the list.
-		/// </summary>
-		public void Clear()
-		{
-			listeners.Clear();
-		}
-		
-		/// <summary>
-		/// Checks to see if the list contains the specified listener
-		/// </summary>
-		/// <param name="listener">
-		/// The listener to search for.
-		/// </param>
-		/// <return>
-		/// true if list contains listener; false otherwise.
-		/// </return>
-		public bool Contains(object listener)
-		{
-			return listeners.Contains(listener);
-		}
-		
-		/// <summary>
-		/// Copies a section of the current TraceListenerCollection to
-		/// the specified array at the specified index.
-		/// </summary>
-		/// <param name="listeners">
-		/// Array to copy listeners to.
-		/// </param>
-		/// <param name="index">
-		/// Starting index of copy
-		/// </param>
-		[MonoTODO]
-		public void CopyTo(Array listeners, int index)
-		{
-			try {
-				this.listeners.CopyTo(listeners, index);
-			} catch {
-				
-			}
-		}
-		
-		/// <summary>
-		/// Returns an enumerator for the list of listeners.
-		/// </summary>
-		/// <return>
-		/// List Enumerator of type IEnumerator.
-		/// </return>
-		public IEnumerator GetEnumerator()
-		{
-			return listeners.GetEnumerator();
-		}
-		
-		/// <summary>
-		/// Gets the index of the specified listener.
-		/// </summary>
-		/// <param name="listener">
-		/// The listener to search for
-		/// </param>
-		/// <return>
-		/// The index of the listener in the list, if it exists.
-		/// </return>
-		[MonoTODO]
-		public int IndexOf(object listener)
-		{
-			// TODO: we may have to add in some type-checking here.
-			return listeners.IndexOf(listener);
-		}
-		
-		/// <summary>
-		/// Inserts the specified listener into the list at the specified index.
-		/// </summary>
-		/// <param name="index">
-		/// Location in the list to insert the listener.
-		/// </param>
-		/// <param name="listener">
-		/// The TraceListener to insert into the list.
-		/// </param>
-		public void Insert(int index, object listener)
-		{
-			listeners.Insert(index, listener);
-		}
-		
-		/// <summary>
-		/// Removes the listener with the specified name from the list, if it exists.
-		/// </summary>
-		/// <param name="name">
-		/// Name of listener to remove
-		/// </param>
-		[MonoTODO]
-		public void Remove(object name)
-		{
-			try {
-				// TODO: may use an enumerator here.
-				for(int i = 0; i < listeners.Count; i++)
-				{
-					TraceListener listener = (TraceListener) listeners[i];
-					if(listener == null)
-						continue;
-					if(listener.Name.Equals(name))
-						listeners.Remove(listener);
-				}
-			} catch {
-				throw new ArgumentException("Listener is not in list.");
-			}
-		}
-		
-		/// <summary>
-		/// Removes the specified listener from the list
-		/// </summary>
-		/// <param name="listener">
-		/// The listener to remove.
-		/// </param>
-		public void Remove(TraceListener listener)
-		{
-			listeners.Remove(listener);
-		}
-		
-		/// <summary>
-		/// Removes the listener at the specified index.
-		/// </summary>
-		/// <param name="index">
-		/// Location of the listener to remove.
-		/// </param>
-		public void RemoveAt(int index)
-		{
-			try {
-				listeners.RemoveAt(index);
-			} catch(Exception e) {
-				throw new ArgumentOutOfRangeException(e.ToString());
-			}
-		}
-		
-		~TraceListenerCollection()
-		{
-			listeners = null;
-		}
-		
-		public bool IsReadOnly
-		{
-			get
-			{
-				return isReadOnly;
-			}
-		}
-		
-		public bool IsFixedSize
-		{
-			get
-			{
-				return isFixedSize;
-			}
-		}
-		
-		public object SyncRoot
-		{
-			get
-			{
-				return this;
-			}
-		}
-		
-		public bool IsSynchronized
-		{
-			get
-			{
-				return isSynchronized;
-			}
-		}
-	}
-}
+//
+// System.Diagnostics.TraceListenerCollection.cs
+//
+// Authors:
+//   Jonathan Pryor ([email protected])
+//
+// Comments from John R. Hicks <[email protected]> original
+// implementation.
+//
+// (C) 2002 Jonathan Pryor
+//
+
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Globalization;
+
+namespace System.Diagnostics {
+
+	/// <summary>
+	/// Provides a list of TraceListener objects.
+	/// </summary>
+	public class TraceListenerCollection : IList, ICollection, IEnumerable {
+
+		private ArrayList listeners = new ArrayList ();
+
+		public TraceListenerCollection ()
+		{
+			Add (new DefaultTraceListener ());
+		}
+
+		/// <summary>
+		/// Returns the number of items in the list
+		/// </summary>
+		/// <value>
+		/// The number of items
+		/// </value>
+		public int Count{
+			get {return listeners.Count;}
+		}
+
+		/// <summary>
+		/// Gets the first TraceListener in the list with the
+		/// specified name.
+		/// </summary>
+		public TraceListener this [string name] {
+			get {
+				foreach (TraceListener listener in listeners) {
+					if (listener.Name == name)
+						return listener;
+				}
+				return null;
+			}
+		}
+
+		public object this [int index] {
+			get {return listeners[index];}
+			set {listeners[index] = value;}
+		}
+
+		bool ICollection.IsSynchronized {
+			get {return listeners.IsSynchronized;}
+		}
+
+		object ICollection.SyncRoot {
+			get {return listeners.SyncRoot;}
+		}
+
+		bool IList.IsFixedSize {
+			get {return listeners.IsFixedSize;}
+		}
+
+		bool IList.IsReadOnly {
+			get {return listeners.IsReadOnly;}
+		}
+
+		/// <summary>
+		/// Adds a TraceListener to the list.
+		/// </summary>
+		/// <param name="listener">
+		/// The TraceListener being added to the list.
+		/// </param>
+		/// <return>
+		/// The position in the list where the listener was inserted.
+		/// </return>
+		public int Add (TraceListener listener)
+		{
+			return listeners.Add (listener);
+		}
+
+		/// <summary>
+		/// Adds an array of TraceListeners to the list.
+		/// </summary>
+		/// <param name="value">
+		/// Array of TraceListeners to add
+		/// </param>
+		public void AddRange (TraceListener[] value)
+		{
+			listeners.AddRange (value);
+		}
+
+		/// <summary>
+		/// Adds the contents of another TraceListenerCollection to this one.
+		/// </summary>
+		/// <param name="value">
+		/// The TraceListenerCollection to copy values from.
+		/// </param>
+		public void AddRange (TraceListenerCollection value)
+		{
+			listeners.AddRange (value.listeners);
+		}
+
+		/// <summary>
+		/// Clears all listeners from the list.
+		/// </summary>
+		public void Clear ()
+		{
+			listeners.Clear ();
+		}
+
+		/// <summary>
+		/// Checks to see if the list contains the specified listener
+		/// </summary>
+		/// <param name="listener">
+		/// The listener to search for.
+		/// </param>
+		/// <return>
+		/// true if list contains listener; false otherwise.
+		/// </return>
+		public bool Contains (TraceListener listener)
+		{
+			return listeners.Contains (listener);
+		}
+
+		/// <summary>
+		/// Copies a section of the current TraceListenerCollection to
+		/// the specified array at the specified index.
+		/// </summary>
+		/// <param name="listeners">
+		/// Array to copy listeners to.
+		/// </param>
+		/// <param name="index">
+		/// Starting index of copy
+		/// </param>
+		public void CopyTo (TraceListener[] listeners, int index)
+		{
+			listeners.CopyTo (listeners, index);
+		}
+
+		/// <summary>
+		/// Returns an enumerator for the list of listeners.
+		/// </summary>
+		/// <return>
+		/// List Enumerator of type IEnumerator.
+		/// </return>
+		public IEnumerator GetEnumerator ()
+		{
+			return listeners.GetEnumerator ();
+		}
+
+		void ICollection.CopyTo (Array array, int index)
+		{
+			listeners.CopyTo (array, index);
+		}
+
+		int IList.Add (object value)
+		{
+			if (value is TraceListener)
+				return listeners.Add (value);
+			throw new NotSupportedException (Locale.GetText (
+				"You can only add TraceListener objects to the collection"));
+		}
+
+		bool IList.Contains (object value)
+		{
+			if (value is TraceListener)
+				return listeners.Contains (value);
+			return false;
+		}
+
+		int IList.IndexOf (object value)
+		{
+			if (value is TraceListener)
+				return listeners.IndexOf (value);
+			return -1;
+		}
+
+		void IList.Insert (int index, object value)
+		{
+			if (value is TraceListener) {
+				listeners.Insert (index, value);
+				return;
+			}
+			throw new NotSupportedException (Locale.GetText (
+				"You can only insert TraceListener objects into the collection"));
+		}
+
+		void IList.Remove (object value)
+		{
+			if (value is TraceListener)
+				listeners.Remove (value);
+		}
+
+		/// <summary>
+		/// Gets the index of the specified listener.
+		/// </summary>
+		/// <param name="listener">
+		/// The listener to search for
+		/// </param>
+		/// <return>
+		/// The index of the listener in the list, if it exists.
+		/// </return>
+		public int IndexOf (TraceListener listener)
+		{
+			return listeners.IndexOf (listener);
+		}
+
+		/// <summary>
+		/// Inserts the specified listener into the list at the specified index.
+		/// </summary>
+		/// <param name="index">
+		/// Location in the list to insert the listener.
+		/// </param>
+		/// <param name="listener">
+		/// The TraceListener to insert into the list.
+		/// </param>
+		public void Insert (int index, TraceListener listener)
+		{
+			listeners.Insert (index, listener);
+		}
+
+		/// <summary>
+		/// Removes the listener with the specified name from the list, if it 
+		/// exists.
+		/// </summary>
+		/// <param name="name">
+		/// Name of listener to remove
+		/// </param>
+		public void Remove (string name)
+		{
+			TraceListener found = null;
+
+			foreach (TraceListener listener in listeners) {
+				if (listener.Name == name) {
+					found = listener;
+					break;
+				}
+			}
+
+			if (found != null)
+				listeners.Remove (found);
+			else
+				throw new ArgumentException (Locale.GetText (
+					"TraceListener " + name + " was not in the collection"));
+		}
+
+		/// <summary>
+		/// Removes the specified listener from the list
+		/// </summary>
+		/// <param name="listener">
+		/// The listener to remove.
+		/// </param>
+		public void Remove (TraceListener listener)
+		{
+			listeners.Remove (listener);
+		}
+
+		/// <summary>
+		/// Removes the listener at the specified index.
+		/// </summary>
+		/// <param name="index">
+		/// Location of the listener to remove.
+		/// </param>
+		public void RemoveAt (int index)
+		{
+			listeners.RemoveAt (index);
+		}
+	}
+}
+