(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System / System.Diagnostics / TextWriterTraceListener.cs
blob3a570ea11773eb3a8d81448785157aba65738fff
1 //
2 // System.Diagnostics.TextWriterTraceListener.cs
3 //
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
6 //
7 // Authors:
8 // Jonathan Pryor (jonpryor@vt.edu)
9 //
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:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
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.
34 using System;
35 using System.IO;
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)
49 : this (stream, "")
53 public TextWriterTraceListener (string fileName)
54 : this (fileName, "")
58 public TextWriterTraceListener (TextWriter writer)
59 : this (writer, "")
63 public TextWriterTraceListener (Stream stream, string name)
64 : base (name != null ? name : "")
66 if (stream == null)
67 throw new ArgumentNullException ("stream");
68 writer = new StreamWriter (stream);
71 public TextWriterTraceListener (string fileName, string name)
72 : base (name != null ? name : "")
74 if (fileName == null)
75 throw new ArgumentNullException ("fileName");
76 writer = File.AppendText (fileName);
79 public TextWriterTraceListener (TextWriter writer, string name)
80 : base (name != null ? name : "")
82 if (writer == null)
83 throw new ArgumentNullException ("writer");
84 this.writer = writer;
87 public TextWriter Writer {
88 get {return writer;}
89 set {writer = value;}
92 public override void Close ()
94 if (writer != null) {
95 writer.Flush ();
96 writer.Close ();
97 writer = null;
101 protected override void Dispose (bool disposing)
103 if (disposing)
104 Close ();
106 base.Dispose (disposing);
109 public override void Flush ()
111 if (writer != null)
112 writer.Flush ();
115 public override void Write (string message)
117 if (writer != null) {
118 if (NeedIndent)
119 WriteIndent ();
120 writer.Write (message);
124 public override void WriteLine (string message)
126 if (writer != null) {
127 if (NeedIndent)
128 WriteIndent ();
129 writer.WriteLine (message);
130 NeedIndent = true;