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