2 // System.Diagnostics.TraceListener.cs
5 // Jonathan Pryor (jonpryor@vt.edu)
7 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
8 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
10 // (C) 2002 Jonathan Pryor
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Diagnostics;
37 namespace System.Diagnostics {
39 public abstract class TraceListener : MarshalByRefObject, IDisposable {
42 private int indentLevel = 0;
45 private int indentSize = 4;
47 private string name = null;
48 private bool needIndent = true;
50 protected TraceListener () : this ("")
54 protected TraceListener (string name)
59 public int IndentLevel {
60 get {return indentLevel;}
61 set {indentLevel = value;}
64 public int IndentSize {
65 get {return indentSize;}
66 set {indentSize = value;}
69 public virtual string Name {
74 protected bool NeedIndent {
75 get {return needIndent;}
76 set {needIndent = value;}
79 public virtual void Close ()
84 public void Dispose ()
87 GC.SuppressFinalize (this);
90 protected virtual void Dispose (bool disposing)
94 public virtual void Fail (string message)
99 public virtual void Fail (string message, string detailMessage)
101 WriteLine ("---- DEBUG ASSERTION FAILED ----");
102 WriteLine ("---- Assert Short Message ----");
104 WriteLine ("---- Assert Long Message ----");
105 WriteLine (detailMessage);
109 public virtual void Flush ()
113 public virtual void Write (object o)
115 Write (o.ToString());
118 public abstract void Write (string message);
120 public virtual void Write (object o, string category)
122 Write (o.ToString(), category);
125 public virtual void Write (string message, string category)
127 Write (category + ": " + message);
130 protected virtual void WriteIndent ()
132 // Must set NeedIndent to false before Write; otherwise, we get endless
133 // recursion with Write->WriteIndent->Write->WriteIndent...*boom*
135 String indent = new String (' ', IndentLevel*IndentSize);
139 public virtual void WriteLine (object o)
141 WriteLine (o.ToString());
144 public abstract void WriteLine (string message);
146 public virtual void WriteLine (object o, string category)
148 WriteLine (o.ToString(), category);
151 public virtual void WriteLine (string message, string category)
153 WriteLine (category + ": " + message);