Mercurial > pub > ImplabNet
annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 47:b181f7bcb259 interactive logger
refactoring, interactive tarce log almost complete
| author | cin |
|---|---|
| date | Thu, 17 Apr 2014 18:49:36 +0400 |
| parents | 7c2369f580b8 |
| children | d9d794b61bb9 |
| rev | line source |
|---|---|
| 36 | 1 using System; |
| 2 using System.Collections.Generic; | |
| 3 using System.Linq; | |
| 4 using System.Text; | |
| 5 | |
| 6 namespace Implab.Diagnostics { | |
| 40 | 7 public class ConsoleTraceListener: TextListenerBase { |
| 36 | 8 |
| 9 static readonly object _consoleLock = new object(); | |
| 10 | |
|
43
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
11 public ConsoleTraceListener() |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
12 : base(true) { |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
13 |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
14 } |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
15 |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
16 public ConsoleTraceListener(bool local) |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
17 : base(local) { |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
18 |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
19 } |
|
7c2369f580b8
improved tracing, TextListenerBase can be bound to logical operation scope.
cin
parents:
40
diff
changeset
|
20 |
| 40 | 21 protected override void WriteEntry(TraceContext context, EventText text) { |
| 22 var msg = new StringBuilder(); | |
| 36 | 23 |
| 40 | 24 for (int i = 0; i < text.indent; i++) |
| 36 | 25 msg.Append(" "); |
| 40 | 26 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content); |
| 36 | 27 |
| 28 lock (_consoleLock) { | |
| 29 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1); | |
| 30 Console.WriteLine(msg.ToString()); | |
| 31 } | |
| 32 } | |
| 33 } | |
| 34 } |
