40
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.IO;
|
|
4 using System.Linq;
|
|
5 using System.Text;
|
|
6
|
|
7 namespace Implab.Diagnostics {
|
|
8 public class TextFileListener: TextListenerBase {
|
|
9 readonly TextWriter m_textWriter;
|
|
10
|
44
|
11 public TextFileListener(string fileName, bool local) : base(local) {
|
40
|
12 m_textWriter = File.CreateText(fileName);
|
|
13
|
|
14 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
|
|
15 Register(this);
|
|
16 }
|
|
17
|
|
18 protected override void WriteEntry(TraceContext context, EventText text) {
|
|
19 var msg = new StringBuilder();
|
|
20 for (int i = 0; i < text.indent; i++)
|
|
21 msg.Append(" ");
|
|
22 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
|
|
23
|
|
24 lock (m_textWriter) {
|
|
25 if (!IsDisposed) {
|
47
|
26 // тут гарантировано еще не освобожден m_textWriter
|
40
|
27 m_textWriter.WriteLine(msg.ToString());
|
|
28 m_textWriter.Flush();
|
|
29 }
|
|
30 }
|
|
31 }
|
|
32
|
|
33
|
|
34 protected override void Dispose(bool disposing) {
|
|
35 base.Dispose(disposing);
|
|
36 if (disposing) {
|
47
|
37 // IsDisposed = true
|
40
|
38 lock (m_textWriter) {
|
|
39 Safe.Dispose(m_textWriter);
|
|
40 }
|
|
41 }
|
|
42 }
|
|
43
|
|
44
|
|
45 }
|
|
46 }
|