diff Implab/Diagnostics/ConsoleTraceListener.cs @ 40:fe33f4e02ad5

improved tracing added text listeners (file,console)
author cin
date Tue, 15 Apr 2014 17:52:09 +0400
parents 313f708a50e9
children 7c2369f580b8
line wrap: on
line diff
--- a/Implab/Diagnostics/ConsoleTraceListener.cs	Tue Apr 15 02:46:53 2014 +0400
+++ b/Implab/Diagnostics/ConsoleTraceListener.cs	Tue Apr 15 17:52:09 2014 +0400
@@ -4,29 +4,16 @@
 using System.Text;
 
 namespace Implab.Diagnostics {
-    public class ConsoleTraceListener {
+    public class ConsoleTraceListener: TextListenerBase {
 
         static readonly object _consoleLock = new object();
 
-        public void Subscribe() {
-            LogChannel<TraceEvent>.Default.Events += Default_Events;
-        }
-
-        public void Unsubscribe() {
-            LogChannel<TraceEvent>.Default.Events -= Default_Events;
-        }
+        protected override void WriteEntry(TraceContext context, EventText text) {
+            var msg = new StringBuilder();
 
-        void Default_Events(object sender, ValueEventArgs<TraceEvent> e) {
-            LogEvent((TraceContext)sender, e.Value);
-        }
-
-        void LogEvent(TraceContext context, TraceEvent evt) {
-            var msg = new StringBuilder();
-            for (int i = 0; i < context.CurrentOperation.Level; i++)
+            for (int i = 0; i < text.indent; i++)
                 msg.Append("  ");
-            msg.Append(evt.EventType);
-            msg.AppendFormat("[{0}]: ",context.ThreadId);
-            msg.Append(evt.Message);
+            msg.AppendFormat("[{0}]: {1}", context.ThreadId, text.content);
 
             lock (_consoleLock) {
                 Console.ForegroundColor = (ConsoleColor)(context.ThreadId % 15 + 1);