##// END OF EJS Templates
More verbose output with TextFileListener
cin -
r217:6efb77590b15 v2
parent child
Show More
@@ -1,47 +1,47
1 1 using System;
2 2 using System.IO;
3 3 using System.Text;
4 4
5 5 namespace Implab.Diagnostics {
6 6 public class TextFileListener: ListenerBase {
7 7 readonly TextWriter m_textWriter;
8 8 readonly object m_lock = new object();
9 9
10 10 public TextFileListener(string fileName) {
11 11 m_textWriter = File.CreateText(fileName);
12 12
13 13 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
14 14 }
15 15
16 16 #region implemented abstract members of ListenerBase
17 17
18 18 public override void Write(LogEventArgs args, object entry) {
19 19 var msg = new StringBuilder();
20 20 for (int i = 0; i < args.Operation.Level; i++)
21 21 msg.Append(" ");
22 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, args.Channel, entry);
22 msg.AppendFormat("[{0}]+{3}ms:{1}: {2}", args.ThreadId, args.Channel, entry, args.OperationTimeOffset);
23 23
24 24 lock (m_lock) {
25 25 if (!IsDisposed) {
26 26 // тут гарантировано еще не освобожден m_textWriter
27 27 m_textWriter.WriteLine(msg);
28 28 m_textWriter.Flush();
29 29 }
30 30 }
31 31 }
32 32
33 33 #endregion
34 34
35 35 protected override void Dispose(bool disposing) {
36 36 base.Dispose(disposing);
37 37 if (disposing) {
38 38 // IsDisposed = true
39 39 lock (m_lock) {
40 40 Safe.Dispose(m_textWriter);
41 41 }
42 42 }
43 43 }
44 44
45 45
46 46 }
47 47 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now