2 // System.Diagnostics.TextWriterTraceListener.cs
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
8 // Jonathan Pryor (jonpryor@vt.edu)
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.
36 using System
.Diagnostics
;
38 namespace System
.Diagnostics
{
40 public class TextWriterTraceListener
: TraceListener
{
42 private TextWriter writer
;
44 public TextWriterTraceListener () : base ("TextWriter")
48 public TextWriterTraceListener (Stream stream
)
53 public TextWriterTraceListener (string fileName
)
58 public TextWriterTraceListener (TextWriter writer
)
63 public TextWriterTraceListener (Stream stream
, string name
)
64 : base (name
!= null ? name
: "")
67 throw new ArgumentNullException ("stream");
68 writer
= new StreamWriter (stream
);
71 public TextWriterTraceListener (string fileName
, string name
)
72 : base (name
!= null ? name
: "")
75 throw new ArgumentNullException ("fileName");
76 writer
= new StreamWriter (new FileStream (fileName
, FileMode
.Append
, FileAccess
.Write
, FileShare
.ReadWrite
));
79 public TextWriterTraceListener (TextWriter writer
, string name
)
80 : base (name
!= null ? name
: "")
83 throw new ArgumentNullException ("writer");
87 public TextWriter Writer
{
92 public override void Close ()
101 protected override void Dispose (bool disposing
)
106 base.Dispose (disposing
);
109 public override void Flush ()
115 public override void Write (string message
)
117 if (writer
!= null) {
120 writer
.Write (message
);
124 public override void WriteLine (string message
)
126 if (writer
!= null) {
129 writer
.WriteLine (message
);