blob: e2c6129640dd9709b4adccfca2c87768ba8fd119 (
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
|
//
// System.Diagnostics.TextWriterTraceListener.cs
//
// Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
// can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2002 Jonathan Pryor
//
using System;
using System.IO;
using System.Diagnostics;
namespace System.Diagnostics {
public class TextWriterTraceListener : TraceListener {
private TextWriter writer;
public TextWriterTraceListener () : base ("TextWriter")
{
}
public TextWriterTraceListener (Stream stream)
: this (stream, "")
{
}
public TextWriterTraceListener (string fileName)
: this (fileName, "")
{
}
public TextWriterTraceListener (TextWriter writer)
: this (writer, "")
{
}
public TextWriterTraceListener (Stream stream, string name)
: base (name != null ? name : "")
{
if (stream == null)
throw new ArgumentNullException ("stream");
writer = new StreamWriter (stream);
}
public TextWriterTraceListener (string fileName, string name)
: base (name != null ? name : "")
{
if (fileName == null)
throw new ArgumentNullException ("fileName");
writer = new StreamWriter (File.OpenWrite (fileName));
}
public TextWriterTraceListener (TextWriter writer, string name)
: base (name != null ? name : "")
{
if (writer == null)
throw new ArgumentNullException ("writer");
this.writer = writer;
}
public TextWriter Writer {
get {return writer;}
set {writer = value;}
}
public override void Close ()
{
if (writer != null) {
writer.Flush ();
writer.Close ();
writer = null;
}
}
protected override void Dispose (bool disposing)
{
if (disposing)
Close ();
}
public override void Flush ()
{
writer.Flush ();
}
public override void Write (string message)
{
if (NeedIndent)
WriteIndent ();
writer.Write (message);
}
public override void WriteLine (string message)
{
if (NeedIndent)
WriteIndent ();
writer.WriteLine (message);
NeedIndent = true;
}
}
}
|