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