annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 197:86187b01c4e0

fixed: the error handler should not handle handlers errors
author cin
date Thu, 01 Sep 2016 10:43:31 +0300
parents 04d4c92d0f28
children
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.Text;
313f708a50e9 improved log concept
cin
parents:
diff changeset
3
313f708a50e9 improved log concept
cin
parents:
diff changeset
4 namespace Implab.Diagnostics {
134
04d4c92d0f28 Improved logging
cin
parents: 133
diff changeset
5 public class ConsoleTraceListener: ListenerBase {
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
6
313f708a50e9 improved log concept
cin
parents:
diff changeset
7 static readonly object _consoleLock = new object();
313f708a50e9 improved log concept
cin
parents:
diff changeset
8
134
04d4c92d0f28 Improved logging
cin
parents: 133
diff changeset
9 public override void Write(LogEventArgs args, object entry) {
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
10 var msg = new StringBuilder();
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
11
134
04d4c92d0f28 Improved logging
cin
parents: 133
diff changeset
12 for (int i = 0; i < args.Operation.Level; i++)
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
13 msg.Append(" ");
134
04d4c92d0f28 Improved logging
cin
parents: 133
diff changeset
14 msg.AppendFormat("[{0}]: {1}", args.ThreadId, entry);
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
15
313f708a50e9 improved log concept
cin
parents:
diff changeset
16 lock (_consoleLock) {
133
cin
parents: 109
diff changeset
17 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1);
92
4c0e5ef99986 rewritten tracing
cin
parents: 48
diff changeset
18 Console.WriteLine(msg);
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
19 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
20 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
21 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
22 }