1 // ***********************************************************************
2 // Copyright (c) 2008-2013 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
32 namespace NUnit.Engine.Internal
34 namespace NUnit.Framework.Internal
36 namespace NUnit.Common
40 /// A trace listener that writes to a separate file per domain
41 /// and process using it.
43 public class InternalTraceWriter : TextWriter
46 object myLock = new object();
50 /// Construct an InternalTraceWriter that writes to a file.
52 /// <param name="logPath">Path to the file to use</param>
53 public InternalTraceWriter(string logPath)
55 var streamWriter = new StreamWriter(new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.Write));
56 streamWriter.AutoFlush = true;
57 this.writer = streamWriter;
62 /// Construct an InternalTraceWriter that writes to a
63 /// TextWriter provided by the caller.
65 /// <param name="writer"></param>
66 public InternalTraceWriter(TextWriter writer)
72 /// Returns the character encoding in which the output is written.
74 /// <returns>The character encoding in which the output is written.</returns>
75 public override System.Text.Encoding Encoding
77 get { return writer.Encoding; }
81 /// Writes a character to the text string or stream.
83 /// <param name="value">The character to write to the text stream.</param>
84 public override void Write(char value)
93 /// Writes a string to the text string or stream.
95 /// <param name="value">The string to write.</param>
96 public override void Write(string value)
105 /// Writes a string followed by a line terminator to the text string or stream.
107 /// <param name="value">The string to write. If <paramref name="value" /> is null, only the line terminator is written.</param>
108 public override void WriteLine(string value)
110 writer.WriteLine(value);
114 /// Releases the unmanaged resources used by the <see cref="T:System.IO.TextWriter" /> and optionally releases the managed resources.
116 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
117 protected override void Dispose(bool disposing)
119 if (disposing && writer != null)
126 base.Dispose(disposing);
130 /// Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
132 public override void Flush()
134 if ( writer != null )