Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/ConsoleTraceListener.cs @ 192:f1da3afc3521 release v2.1
Слияние с v2
author | cin |
---|---|
date | Fri, 22 Apr 2016 13:10:34 +0300 |
parents | 04d4c92d0f28 |
children |
comparison
equal
deleted
inserted
replaced
71:1714fd8678ef | 192:f1da3afc3521 |
---|---|
1 using System; | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Text; | 2 using System.Text; |
5 | 3 |
6 namespace Implab.Diagnostics { | 4 namespace Implab.Diagnostics { |
7 public class ConsoleTraceListener: TextListenerBase { | 5 public class ConsoleTraceListener: ListenerBase { |
8 | 6 |
9 static readonly object _consoleLock = new object(); | 7 static readonly object _consoleLock = new object(); |
10 | 8 |
11 public ConsoleTraceListener() | 9 public override void Write(LogEventArgs args, object entry) { |
12 : base(true) { | |
13 | |
14 } | |
15 | |
16 public ConsoleTraceListener(bool global) | |
17 : base(global) { | |
18 | |
19 } | |
20 | |
21 protected override void WriteEntry(TraceContext context, EventText text, string channel) { | |
22 var msg = new StringBuilder(); | 10 var msg = new StringBuilder(); |
23 | 11 |
24 for (int i = 0; i < text.indent; i++) | 12 for (int i = 0; i < args.Operation.Level; i++) |
25 msg.Append(" "); | 13 msg.Append(" "); |
26 msg.AppendFormat("[{0}]:{1}: {2}", context.ThreadId, channel, text.content); | 14 msg.AppendFormat("[{0}]: {1}", args.ThreadId, entry); |
27 | 15 |
28 lock (_consoleLock) { | 16 lock (_consoleLock) { |
29 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1); | 17 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); |
30 Console.WriteLine(msg.ToString()); | 18 Console.WriteLine(msg); |
31 } | 19 } |
32 } | 20 } |
33 } | 21 } |
34 } | 22 } |