diff Implab/Diagnostics/Trace.cs @ 281:e0916ddc9950 v3 tip

code cleanup and refactoring
author cin
date Fri, 01 Jun 2018 21:35:24 +0300
parents f07be402ab02
children
line wrap: on
line diff
--- a/Implab/Diagnostics/Trace.cs	Fri May 25 19:15:26 2018 +0300
+++ b/Implab/Diagnostics/Trace.cs	Fri Jun 01 21:35:24 2018 +0300
@@ -1,4 +1,7 @@
-using System;
+// enable System.Diagnostics trace methods
+#define TRACE
+
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
@@ -9,7 +12,21 @@
 namespace Implab.Diagnostics {
     public static class Trace<T> {
 
-        public static TraceSource TraceSource { get; } = new TraceSource(typeof(T).Name);
+        static Lazy<TraceSource> _traceSource = new Lazy<TraceSource>(CreateChannel, LazyThreadSafetyMode.ExecutionAndPublication);
+
+        static int _nextId;
+
+        static TraceSource CreateChannel() {
+            var id = Interlocked.Increment(ref _nextId);
+            return new TraceSource(typeof(T).Name);
+        }
+
+        public static TraceSource TraceSource { get { return _traceSource.Value; } }
+
+        public static IDisposable Subscribe() {
+            
+            throw new NotImplementedException();
+        }
 
 #if NETFX_TRACE_BUG
         readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>();