annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 210:5dc21f6a3222 v2

Code review for RunnableComponent Added StaApartment class based on System.Windows.Forms.Application message loop
author cin
date Mon, 20 Mar 2017 17:44:18 +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 }