annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 70:0349189d2564

refactoring
author cin
date Wed, 03 Sep 2014 11:57:43 +0400
parents d9d794b61bb9
children 4c0e5ef99986
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
1 using System;
313f708a50e9 improved log concept
cin
parents:
diff changeset
2 using System.Collections.Generic;
313f708a50e9 improved log concept
cin
parents:
diff changeset
3 using System.Linq;
313f708a50e9 improved log concept
cin
parents:
diff changeset
4 using System.Text;
313f708a50e9 improved log concept
cin
parents:
diff changeset
5
313f708a50e9 improved log concept
cin
parents:
diff changeset
6 namespace Implab.Diagnostics {
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
7 public class ConsoleTraceListener: TextListenerBase {
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
8
313f708a50e9 improved log concept
cin
parents:
diff changeset
9 static readonly object _consoleLock = new object();
313f708a50e9 improved log concept
cin
parents:
diff changeset
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
48
d9d794b61bb9 Interactive tracing
cin
parents: 43
diff changeset
16 public ConsoleTraceListener(bool global)
d9d794b61bb9 Interactive tracing
cin
parents: 43
diff changeset
17 : base(global) {
43
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
48
d9d794b61bb9 Interactive tracing
cin
parents: 43
diff changeset
21 protected override void WriteEntry(TraceContext context, EventText text, string channel) {
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
22 var msg = new StringBuilder();
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
23
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
24 for (int i = 0; i < text.indent; i++)
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
25 msg.Append(" ");
48
d9d794b61bb9 Interactive tracing
cin
parents: 43
diff changeset
26 msg.AppendFormat("[{0}]:{1}: {2}", context.ThreadId, channel, text.content);
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
27
313f708a50e9 improved log concept
cin
parents:
diff changeset
28 lock (_consoleLock) {
313f708a50e9 improved log concept
cin
parents:
diff changeset
29 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1);
313f708a50e9 improved log concept
cin
parents:
diff changeset
30 Console.WriteLine(msg.ToString());
313f708a50e9 improved log concept
cin
parents:
diff changeset
31 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
32 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
33 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
34 }