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
|
40
|
11 protected override void WriteEntry(TraceContext context, EventText text) {
|
|
12 var msg = new StringBuilder();
|
36
|
13
|
40
|
14 for (int i = 0; i < text.indent; i++)
|
36
|
15 msg.Append(" ");
|
40
|
16 msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
|
36
|
17
|
|
18 lock (_consoleLock) {
|
|
19 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1);
|
|
20 Console.WriteLine(msg.ToString());
|
|
21 }
|
|
22 }
|
|
23 }
|
|
24 }
|