Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TraceListener.cs « System.Diagnostics « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b32ced8eb1b87f30c12db8ff1b6e31fa4ace6a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// System.Diagnostics.TraceListener.cs
//
// Authors:
//   Jonathan Pryor (jonpryor@vt.edu)
//
// Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation 
// can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
//
// (C) 2002 Jonathan Pryor
//

using System;
using System.Diagnostics;

namespace System.Diagnostics {

	public abstract class TraceListener : MarshalByRefObject, IDisposable {

		[ThreadStatic]
		private int indentLevel = 0;

		[ThreadStatic]
		private int indentSize = 4;

		private string name = null;
		private bool needIndent = false;

		protected TraceListener () : this ("")
		{
		}

		protected TraceListener (string name)
		{
			Name = name;
		}

		public int IndentLevel {
			get {return indentLevel;}
			set {indentLevel = value;}
		}

		public int IndentSize {
			get {return indentSize;}
			set {indentSize = value;}
		}

		public virtual string Name {
			get {return name;}
			set {name = value;}
		}

		protected bool NeedIndent {
			get {return needIndent;}
			set {needIndent = value;}
		}

		public virtual void Close ()
		{
			Dispose ();
		}

		public void Dispose ()
		{
			Dispose (true);
			GC.SuppressFinalize (this);
		}

		protected virtual void Dispose (bool disposing)
		{
		}

		public virtual void Fail (string message)
		{
			Fail (message, "");
		}

		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 ("");
		}

		public virtual void Flush ()
		{
		}

		public virtual void Write (object o)
		{
			Write (o.ToString());
		}

		public abstract void Write (string message);

		public virtual void Write (object o, string category)
		{
			Write (o.ToString(), category);
		}

		public virtual void Write (string message, string category)
		{
			Write (category + ": " + message);
		}

		protected virtual void WriteIndent ()
		{
			// Must set NeedIndent to false before Write; otherwise, we get endless
			// recursion with Write->WriteIndent->Write->WriteIndent...*boom*
			NeedIndent = false;
			String indent = new String (' ', IndentLevel*IndentSize);
			Write (indent);
		}

		public virtual void WriteLine (object o)
		{
			WriteLine (o.ToString());
		}

		public abstract void WriteLine (string message);

		public virtual void WriteLine (object o, string category)
		{
			WriteLine (o.ToString(), category);
		}

		public virtual void WriteLine (string message, string category)
		{
			WriteLine (category + ": " + message);
		}
	}
}