[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Common / Logging / InternalTraceWriter.cs
1 // ***********************************************************************
2 // Copyright (c) 2008-2013 Charlie Poole
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System.IO;
30
31 #if NUNIT_ENGINE
32 namespace NUnit.Engine.Internal
33 #elif NUNIT_FRAMEWORK
34 namespace NUnit.Framework.Internal
35 #else
36 namespace NUnit.Common
37 #endif
38 {
39     /// <summary>
40     /// A trace listener that writes to a separate file per domain
41     /// and process using it.
42     /// </summary>
43     public class InternalTraceWriter : TextWriter
44     {
45         TextWriter writer;
46         object myLock = new object();
47
48 #if !PORTABLE
49         /// <summary>
50         /// Construct an InternalTraceWriter that writes to a file.
51         /// </summary>
52         /// <param name="logPath">Path to the file to use</param>
53         public InternalTraceWriter(string logPath)
54         {
55             var streamWriter = new StreamWriter(new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.Write));
56             streamWriter.AutoFlush = true;
57             this.writer = streamWriter;
58         }
59 #endif
60
61         /// <summary>
62         /// Construct an InternalTraceWriter that writes to a 
63         /// TextWriter provided by the caller.
64         /// </summary>
65         /// <param name="writer"></param>
66         public InternalTraceWriter(TextWriter writer)
67         {
68             this.writer = writer;
69         }
70
71         /// <summary>
72         /// Returns the character encoding in which the output is written.
73         /// </summary>
74         /// <returns>The character encoding in which the output is written.</returns>
75         public override System.Text.Encoding Encoding
76         {
77             get { return writer.Encoding; }
78         }
79
80         /// <summary>
81         /// Writes a character to the text string or stream.
82         /// </summary>
83         /// <param name="value">The character to write to the text stream.</param>
84         public override void Write(char value)
85         {
86             lock (myLock)
87             {
88                 writer.Write(value);
89             }
90         }
91
92         /// <summary>
93         /// Writes a string to the text string or stream.
94         /// </summary>
95         /// <param name="value">The string to write.</param>
96         public override void Write(string value)
97         {
98             lock (myLock)
99             {
100                 base.Write(value);
101             }
102         }
103
104         /// <summary>
105         /// Writes a string followed by a line terminator to the text string or stream.
106         /// </summary>
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)
109         {
110             writer.WriteLine(value);
111         }
112
113         /// <summary>
114         /// Releases the unmanaged resources used by the <see cref="T:System.IO.TextWriter" /> and optionally releases the managed resources.
115         /// </summary>
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)
118         {
119             if (disposing && writer != null)
120             {
121                 writer.Flush();
122                 writer.Dispose();
123                 writer = null;
124             }
125
126             base.Dispose(disposing);
127         }
128
129         /// <summary>
130         /// Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
131         /// </summary>
132         public override void Flush()
133         {
134             if ( writer != null )
135                 writer.Flush();
136         }
137     }
138 }