Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/ConsoleTraceListener.cs @ 134:04d4c92d0f28 v2
Improved logging
| author | cin |
|---|---|
| date | Wed, 11 Feb 2015 02:12:15 +0300 |
| parents | 6c49d02a9a05 |
| children |
comparison
equal
deleted
inserted
replaced
| 133:6c49d02a9a05 | 134:04d4c92d0f28 |
|---|---|
| 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(LogEventArgs args, 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}", args.ThreadId, text.content); | 14 msg.AppendFormat("[{0}]: {1}", args.ThreadId, entry); |
| 27 | 15 |
| 28 lock (_consoleLock) { | 16 lock (_consoleLock) { |
| 29 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); | 17 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); |
| 30 Console.WriteLine(msg); | 18 Console.WriteLine(msg); |
| 31 } | 19 } |
