ConsoleTraceListener.cs
24 lines
| 755 B
| text/x-csharp
|
CSharpLexer
cin
|
r36 | using System; | ||
using System.Collections.Generic; | ||||
using System.Linq; | ||||
using System.Text; | ||||
namespace Implab.Diagnostics { | ||||
cin
|
r40 | public class ConsoleTraceListener: TextListenerBase { | ||
cin
|
r36 | |||
static readonly object _consoleLock = new object(); | ||||
cin
|
r40 | protected override void WriteEntry(TraceContext context, EventText text) { | ||
var msg = new StringBuilder(); | ||||
cin
|
r36 | |||
cin
|
r40 | for (int i = 0; i < text.indent; i++) | ||
cin
|
r36 | msg.Append(" "); | ||
cin
|
r40 | msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content); | ||
cin
|
r36 | |||
lock (_consoleLock) { | ||||
Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1); | ||||
Console.WriteLine(msg.ToString()); | ||||
} | ||||
} | ||||
} | ||||
} | ||||