comparison Implab/Diagnostics/TextFileListener.cs @ 92:4c0e5ef99986 v2

rewritten tracing
author cin
date Wed, 22 Oct 2014 18:37:56 +0400
parents d9d794b61bb9
children 04d4c92d0f28
comparison
equal deleted inserted replaced
91:cdaaf4792c22 92:4c0e5ef99986
1 using System; 1 using System;
2 using System.Collections.Generic;
3 using System.IO; 2 using System.IO;
4 using System.Linq;
5 using System.Text; 3 using System.Text;
6 4
7 namespace Implab.Diagnostics { 5 namespace Implab.Diagnostics {
8 public class TextFileListener: TextListenerBase { 6 public class TextFileListener: TextListenerBase {
9 readonly TextWriter m_textWriter; 7 readonly TextWriter m_textWriter;
14 12
15 m_textWriter.WriteLine("LOG {0}", DateTime.Now); 13 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
16 Register(this); 14 Register(this);
17 } 15 }
18 16
19 protected override void WriteEntry(TraceContext context, EventText text, string channel) { 17 protected override void WriteEntry(LogEventArgs args, EventText text, string channel) {
20 var msg = new StringBuilder(); 18 var msg = new StringBuilder();
21 for (int i = 0; i < text.indent; i++) 19 for (int i = 0; i < text.indent; i++)
22 msg.Append(" "); 20 msg.Append(" ");
23 msg.AppendFormat("[{0}]:{1}: {2}", context.ThreadId, channel, text.content); 21 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, channel, text.content);
24 22
25 lock (m_textWriter) { 23 lock (m_textWriter) {
26 if (!IsDisposed) { 24 if (!IsDisposed) {
27 // тут гарантировано еще не освобожден m_textWriter 25 // тут гарантировано еще не освобожден m_textWriter
28 m_textWriter.WriteLine(msg.ToString()); 26 m_textWriter.WriteLine(msg);
29 m_textWriter.Flush(); 27 m_textWriter.Flush();
30 } 28 }
31 } 29 }
32 } 30 }
33 31