annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 129:471f596b2603 v2

Added SharedLock to synchronization routines
author cin
date Thu, 29 Jan 2015 18:31:06 +0300
parents 1b7ebcc52e5a
children 6c49d02a9a05
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
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
21 protected override void WriteEntry(LogEventArgs args, 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(" ");
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
26 msg.AppendFormat("[{0}]:{1}: {2}", args.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) {
109
1b7ebcc52e5a minor fixes
cin
parents: 92
diff changeset
29 //Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1);
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
30 Console.WriteLine(msg);
36
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 }