annotate Implab/Diagnostics/ConsoleTraceListener.cs @ 212:a01d9df88d74 v2

Added class Trace<T> to manage channels for individual classes, if SomeClass uses Trace<SomeClass> it sould be marked with TraceSourceAttribute
author cin
date Tue, 04 Apr 2017 12:04:05 +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 }