2 // System.Diagnostics.TraceImpl.cs
5 // Jonathan Pryor (jonpryor@vt.edu)
7 // (C) 2002 Jonathan Pryor
12 using System.Diagnostics;
13 using System.Configuration;
15 namespace System.Diagnostics {
17 internal class TraceImpl {
19 private static object lock_ = new object ();
21 private static bool autoFlush;
24 private static int indentLevel = 0;
27 private static int indentSize;
29 // Grab the .config file stuff.
31 // There are some ordering issues with the .config file.
33 // The DiagnosticsConfigurationHandler assumes that the TraceImpl.Listeners
34 // collection exists (so it can initialize the DefaultTraceListener and
35 // add/remove existing listeners).
37 // When is the .config file read? That's somewhat undefined. The .config
38 // file will be read the first time someone calls
39 // ConfigurationSettings.GetConfig(), but when that occurs is
42 // Since it's probable that the Trace/Debug classes will be used by the
43 // application, the .config file should be read in before they're used.
45 // Thus, place the initialization here. We can ensure that everything is
46 // initialized before reading in the .config file, which should ensure
47 // that everything is sane.
55 listeners = new TraceListenerCollection ();
57 // Initialize the world
58 System.Collections.IDictionary d = DiagnosticsConfiguration.Settings;
60 // remove warning about d being unused
68 public static bool AutoFlush {
69 get {return autoFlush;}
70 set {autoFlush = value;}
73 public static int IndentLevel {
74 get {return indentLevel;}
78 // Don't need to lock for threadsafety as
79 // TraceListener.IndentLevel is [ThreadStatic]
80 foreach (TraceListener t in Listeners) {
81 t.IndentLevel = indentLevel;
86 public static int IndentSize {
87 get {return indentSize;}
91 // Don't need to lock for threadsafety as
92 // TraceListener.IndentSize is [ThreadStatic]
93 foreach (TraceListener t in Listeners) {
94 t.IndentSize = indentSize;
99 private static TraceListenerCollection listeners;
101 public static TraceListenerCollection Listeners {
102 get {return listeners;}
105 // FIXME: According to MSDN, this method should display a dialog box
107 public static void Assert (bool condition)
110 Fail (new StackTrace().ToString());
113 // FIXME: According to MSDN, this method should display a dialog box
115 public static void Assert (bool condition, string message)
121 // FIXME: According to MSDN, this method should display a dialog box
123 public static void Assert (bool condition, string message,
124 string detailMessage)
127 Fail (message, detailMessage);
130 public static void Close ()
133 foreach (TraceListener listener in Listeners) {
139 // FIXME: From testing .NET, this method should display a dialog
141 public static void Fail (string message)
144 foreach (TraceListener listener in Listeners) {
145 listener.Fail (message);
150 // FIXME: From testing .NET, this method should display a dialog
152 public static void Fail (string message, string detailMessage)
155 foreach (TraceListener listener in Listeners) {
156 listener.Fail (message, detailMessage);
161 public static void Flush ()
164 foreach (TraceListener listener in Listeners){
170 public static void Indent ()
173 foreach (TraceListener listener in Listeners) {
174 listener.IndentLevel++;
179 public static void Unindent ()
182 foreach (TraceListener listener in Listeners) {
183 listener.IndentLevel--;
188 public static void Write (object value)
191 foreach (TraceListener listener in Listeners) {
192 listener.Write (value);
200 public static void Write (string message)
203 foreach (TraceListener listener in Listeners) {
204 listener.Write (message);
212 public static void Write (object value, string category)
215 foreach (TraceListener listener in Listeners) {
216 listener.Write (value, category);
224 public static void Write (string message, string category)
227 foreach (TraceListener listener in Listeners) {
228 listener.Write (message, category);
236 public static void WriteIf (bool condition, object value)
242 public static void WriteIf (bool condition, string message)
248 public static void WriteIf (bool condition, object value,
252 Write (value, category);
255 public static void WriteIf (bool condition, string message,
259 Write (message, category);
262 public static void WriteLine (object value)
265 foreach (TraceListener listener in Listeners) {
266 listener.WriteLine (value);
274 public static void WriteLine (string message)
277 foreach (TraceListener listener in Listeners) {
278 listener.WriteLine (message);
286 public static void WriteLine (object value, string category)
289 foreach (TraceListener listener in Listeners) {
290 listener.WriteLine (value, category);
298 public static void WriteLine (string message, string category)
301 foreach (TraceListener listener in Listeners) {
302 listener.WriteLine (message, category);
310 public static void WriteLineIf (bool condition, object value)
316 public static void WriteLineIf (bool condition, string message)
322 public static void WriteLineIf (bool condition, object value,
326 WriteLine (value, category);
329 public static void WriteLineIf (bool condition, string message,
333 WriteLine (message, category);