annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 45:d10034588e38 interactive logger

initial work on interactive logger
author cin
date Thu, 17 Apr 2014 03:05:53 +0400
parents fe33f4e02ad5
children 7c2369f580b8
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
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
11 protected override void WriteEntry(TraceContext context, EventText text) {
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
12 var msg = new StringBuilder();
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
13
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
14 for (int i = 0; i < text.indent; i++)
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
15 msg.Append(" ");
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
16 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
17
313f708a50e9 improved log concept
cin
parents:
diff changeset
18 lock (_consoleLock) {
313f708a50e9 improved log concept
cin
parents:
diff changeset
19 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1);
313f708a50e9 improved log concept
cin
parents:
diff changeset
20 Console.WriteLine(msg.ToString());
313f708a50e9 improved log concept
cin
parents:
diff changeset
21 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
22 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
23 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
24 }