2 // System.Diagnostics.Debug.cs
\r
4 // Author: John R. Hicks <angryjohn69@nc.rr.com>
\r
10 namespace System.Diagnostics
\r
14 /// Provides a set of methods to help debug code
\r
16 public sealed class Debug
\r
18 private static bool autoFlush;
\r
19 private static int indentLevel;
\r
20 private static int indentSize;
\r
21 private static TraceListenerCollection listeners;
\r
28 listeners = new TraceListenerCollection();
\r
32 /// Gets or sets value indicating whether Flush should
\r
33 /// be called on the listeners.
\r
35 public static bool AutoFlush
\r
48 /// Gets or sets indent level
\r
50 public static int IndentLevel
\r
58 indentLevel = value;
\r
63 /// The number of spaces in an indent.
\r
65 public static int IndentSize
\r
78 /// Returns the listeners collection
\r
80 public static TraceListenerCollection Listeners
\r
89 /// Checks for a condition, and prints a stack trace
\r
90 /// if the condition is false.
\r
92 public static void Assert(bool condition)
\r
95 WriteLine(new StackTrace().ToString());
\r
101 /// Checks for a condition, and displays a message if the condition
\r
104 public static void Assert(bool condition, string message)
\r
107 WriteLine(message);
\r
114 /// Checks for a condtion, and displays a message and a detailed message
\r
115 /// string if the condition is false.
\r
117 public static void Assert(bool condition, string message, string detailMessage)
\r
120 WriteLine(message);
\r
122 WriteLine(detailMessage);
\r
129 /// Closes the Debug buffer
\r
131 public static void Close()
\r
133 foreach(TraceListener l in listeners)
\r
140 /// Emits the specified error message.
\r
142 public static void Fail(string message)
\r
144 WriteLine(message);
\r
149 /// Emits the specified error message and detailed error message.
\r
151 public static void Fail(string message, string detailMessage)
\r
153 WriteLine(message);
\r
155 WriteLine(detailMessage);
\r
161 /// Flushes the listeners
\r
163 public static void Flush()
\r
165 foreach(TraceListener l in listeners)
\r
172 /// Increments the indent level
\r
174 public static void Indent()
\r
180 /// Decrements the indent level
\r
182 public static void Unindent()
\r
184 if(indentLevel == 0)
\r
191 /// Writes the value of the specified object's ToString method
\r
192 /// to the listeners.
\r
194 public static void Write(object value)
\r
196 foreach(TraceListener l in listeners)
\r
198 l.Write(value.ToString());
\r
203 /// Writes the specified message to each listener in the Listeners collection.
\r
205 public static void Write(string message)
\r
207 foreach(TraceListener l in listeners)
\r
214 /// Writes the category name and value of the specified object's
\r
215 /// ToString method to each listener in the Listeners collection.
\r
217 public static void Write(object value, string category)
\r
219 foreach(TraceListener l in listeners)
\r
221 l.Write("[" + category + "] " + value.ToString());
\r
226 /// Writes the category name and the specified message
\r
227 /// to each listener in the Listeners collection.
\r
229 public static void Write(string message, string category)
\r
231 foreach(TraceListener l in listeners)
\r
233 l.Write("[" + category + "] " + message);
\r
238 /// Writes the value of the specified object's ToString method
\r
239 /// to each of the listeners if the condition is true.
\r
241 public static void WriteIf(bool condition, object value)
\r
245 foreach(TraceListener l in listeners)
\r
247 l.Write(value.ToString());
\r
253 /// Writes the specified message to each of the listeners
\r
254 /// if the specified condition is true.
\r
256 public static void WriteIf(bool condition, string message)
\r
260 foreach(TraceListener l in listeners)
\r
268 /// Writes the value of the specified object's ToString message
\r
269 /// and category to each of the listeners if the condition is true.
\r
271 public static void WriteIf(bool condition, object value, string category)
\r
275 foreach(TraceListener l in listeners)
\r
277 l.Write("[" + category + "] " + value.ToString());
\r
283 /// Writes the category and specified message to each listener
\r
284 /// if the specified condition is true.
\r
286 public static void WriteIf(bool condition, string message, string category)
\r
290 foreach(TraceListener l in listeners)
\r
292 l.Write("[" + category + "] " + message);
\r
299 /// Writes the value of the object's ToString method,
\r
300 /// followed by a line terminator, to each listener.
\r
302 public static void WriteLine(object value)
\r
304 foreach(TraceListener l in listeners)
\r
306 l.WriteLine(value.ToString());
\r
311 /// Writes the specified message, followed by a line terminator,
\r
312 /// to each listener.
\r
314 public static void WriteLine(string message)
\r
316 foreach(TraceListener l in listeners)
\r
318 l.WriteLine(message);
\r
323 /// Writes the value of the specified object's ToString method,
\r
324 /// along with a category, followed by a line terminator, to each listener.
\r
326 public static void WriteLine(object value, string category)
\r
328 foreach(TraceListener l in listeners)
\r
330 l.WriteLine("[" + category + "] " + value.ToString());
\r
335 /// Writes the specified category and message, followed by a line terminator,
\r
336 /// to each listener.
\r
338 public static void WriteLine(string message, string category)
\r
340 foreach(TraceListener l in listeners)
\r
342 l.WriteLine("[" + category + "] " + message);
\r
347 /// Writes the value of the object's ToString method
\r
348 /// to each listener if the specified condition is true.
\r
350 public static void WriteLineIf(bool condition, object value)
\r
354 foreach(TraceListener l in listeners)
\r
356 l.WriteLine(value.ToString());
\r
362 /// Writes the specified message to each listener
\r
363 /// if the specified condition is true.
\r
365 public static void WriteLineIf(bool condition, string message)
\r
369 foreach(TraceListener l in listeners)
\r
371 l.WriteLine(message);
\r
377 /// Writes the value of the object's ToString method, and a category
\r
378 /// to each listener if the specified condition is true.
\r
380 public static void WriteLineIf(bool condition, object value, string category)
\r
384 foreach(TraceListener l in listeners)
\r
386 l.WriteLine("[" + category + "] " + value.ToString());
\r
392 /// Writes the specified category and message to each listener, followed by a line
\r
393 /// terminator, if the specified condition is true.
\r
395 public static void WriteLineIf(bool condition, string message, string category)
\r
399 foreach(TraceListener l in listeners)
\r
401 l.WriteLine("[" + category + "] " + message);
\r