##// END OF EJS Templates
Рефакторинг, журналирование
cin -
r44:e5ec543feee3 default
parent child
Show More
@@ -1,44 +1,44
1 using System;
1 using System;
2 using System.Collections.Generic;
2 using System.Collections.Generic;
3 using System.IO;
3 using System.IO;
4 using System.Linq;
4 using System.Linq;
5 using System.Text;
5 using System.Text;
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) : base(true) {
11 public TextFileListener(string fileName, bool local) : base(local) {
12 m_textWriter = File.CreateText(fileName);
12 m_textWriter = File.CreateText(fileName);
13
13
14 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
14 m_textWriter.WriteLine("LOG {0}", DateTime.Now);
15 Register(this);
15 Register(this);
16 }
16 }
17
17
18 protected override void WriteEntry(TraceContext context, EventText text) {
18 protected override void WriteEntry(TraceContext context, EventText text) {
19 var msg = new StringBuilder();
19 var msg = new StringBuilder();
20 for (int i = 0; i < text.indent; i++)
20 for (int i = 0; i < text.indent; i++)
21 msg.Append(" ");
21 msg.Append(" ");
22 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
22 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
23
23
24 lock (m_textWriter) {
24 lock (m_textWriter) {
25 if (!IsDisposed) {
25 if (!IsDisposed) {
26 m_textWriter.WriteLine(msg.ToString());
26 m_textWriter.WriteLine(msg.ToString());
27 m_textWriter.Flush();
27 m_textWriter.Flush();
28 }
28 }
29 }
29 }
30 }
30 }
31
31
32
32
33 protected override void Dispose(bool disposing) {
33 protected override void Dispose(bool disposing) {
34 base.Dispose(disposing);
34 base.Dispose(disposing);
35 if (disposing) {
35 if (disposing) {
36 lock (m_textWriter) {
36 lock (m_textWriter) {
37 Safe.Dispose(m_textWriter);
37 Safe.Dispose(m_textWriter);
38 }
38 }
39 }
39 }
40 }
40 }
41
41
42
42
43 }
43 }
44 }
44 }
General Comments 0
You need to be logged in to leave comments. Login now