annotate Implab/Diagnostics/TextFileListener.cs @ 132:5fb2bbffdece v2

minor fixes
author cin
date Sat, 07 Feb 2015 19:41:31 +0300
parents 4c0e5ef99986
children 04d4c92d0f28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
1 using System;
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
2 using System.IO;
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
3 using System.Text;
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
4
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
5 namespace Implab.Diagnostics {
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
6 public class TextFileListener: TextListenerBase {
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
7 readonly TextWriter m_textWriter;
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
8
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
9 public TextFileListener(string fileName, bool global)
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
10 : base(global) {
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
11 m_textWriter = File.CreateText(fileName);
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
12
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
13 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
14 Register(this);
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
15 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
16
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
17 protected override void WriteEntry(LogEventArgs args, EventText text, string channel) {
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
18 var msg = new StringBuilder();
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
19 for (int i = 0; i < text.indent; i++)
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
20 msg.Append(" ");
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
21 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, channel, text.content);
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
22
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
23 lock (m_textWriter) {
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
24 if (!IsDisposed) {
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 44
diff changeset
25 // тут гарантировано еще не освобожден m_textWriter
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
26 m_textWriter.WriteLine(msg);
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
27 m_textWriter.Flush();
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
28 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
29 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
30 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
31
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
32
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
33 protected override void Dispose(bool disposing) {
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
34 base.Dispose(disposing);
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
35 if (disposing) {
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 44
diff changeset
36 // IsDisposed = true
40
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
37 lock (m_textWriter) {
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
38 Safe.Dispose(m_textWriter);
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
39 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
40 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
41 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
42
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
43
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
44 }
fe33f4e02ad5 improved tracing
cin
parents:
diff changeset
45 }