comparison Implab/Diagnostics/TextFileListener.cs @ 48:d9d794b61bb9 interactive logger

Interactive tracing Improved working with tracing contexts
author cin
date Fri, 18 Apr 2014 12:34:45 +0400
parents b181f7bcb259
children 4c0e5ef99986
comparison
equal deleted inserted replaced
47:b181f7bcb259 48:d9d794b61bb9
6 6
7 namespace Implab.Diagnostics { 7 namespace Implab.Diagnostics {
8 public class TextFileListener: TextListenerBase { 8 public class TextFileListener: TextListenerBase {
9 readonly TextWriter m_textWriter; 9 readonly TextWriter m_textWriter;
10 10
11 public TextFileListener(string fileName, bool local) : base(local) { 11 public TextFileListener(string fileName, bool global)
12 : base(global) {
12 m_textWriter = File.CreateText(fileName); 13 m_textWriter = File.CreateText(fileName);
13 14
14 m_textWriter.WriteLine("LOG {0}", DateTime.Now); 15 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
15 Register(this); 16 Register(this);
16 } 17 }
17 18
18 protected override void WriteEntry(TraceContext context, EventText text) { 19 protected override void WriteEntry(TraceContext context, EventText text, string channel) {
19 var msg = new StringBuilder(); 20 var msg = new StringBuilder();
20 for (int i = 0; i < text.indent; i++) 21 for (int i = 0; i < text.indent; i++)
21 msg.Append(" "); 22 msg.Append(" ");
22 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content); 23 msg.AppendFormat("[{0}]:{1}: {2}", context.ThreadId, channel, text.content);
23 24
24 lock (m_textWriter) { 25 lock (m_textWriter) {
25 if (!IsDisposed) { 26 if (!IsDisposed) {
26 // тут гарантировано еще не освобожден m_textWriter 27 // тут гарантировано еще не освобожден m_textWriter
27 m_textWriter.WriteLine(msg.ToString()); 28 m_textWriter.WriteLine(msg.ToString());