36
|
1 using System;
|
|
2 using System.Text;
|
|
3
|
|
4 namespace Implab.Diagnostics {
|
134
|
5 public class ConsoleTraceListener: ListenerBase {
|
36
|
6
|
|
7 static readonly object _consoleLock = new object();
|
|
8
|
134
|
9 public override void Write(LogEventArgs args, object entry) {
|
40
|
10 var msg = new StringBuilder();
|
36
|
11
|
134
|
12 for (int i = 0; i < args.Operation.Level; i++)
|
36
|
13 msg.Append(" ");
|
134
|
14 msg.AppendFormat("[{0}]: {1}", args.ThreadId, entry);
|
36
|
15
|
|
16 lock (_consoleLock) {
|
133
|
17 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1);
|
92
|
18 Console.WriteLine(msg);
|
36
|
19 }
|
|
20 }
|
|
21 }
|
|
22 }
|