comparison 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
comparison
equal deleted inserted replaced
280:f07be402ab02 281:e0916ddc9950
1 using System; 1 // enable System.Diagnostics trace methods
2 #define TRACE
3
4 using System;
2 using System.Collections.Generic; 5 using System.Collections.Generic;
3 using System.Diagnostics; 6 using System.Diagnostics;
4 using System.Linq; 7 using System.Linq;
5 using System.Text; 8 using System.Text;
6 using System.Threading; 9 using System.Threading;
7 using System.Threading.Tasks; 10 using System.Threading.Tasks;
8 11
9 namespace Implab.Diagnostics { 12 namespace Implab.Diagnostics {
10 public static class Trace<T> { 13 public static class Trace<T> {
11 14
12 public static TraceSource TraceSource { get; } = new TraceSource(typeof(T).Name); 15 static Lazy<TraceSource> _traceSource = new Lazy<TraceSource>(CreateChannel, LazyThreadSafetyMode.ExecutionAndPublication);
16
17 static int _nextId;
18
19 static TraceSource CreateChannel() {
20 var id = Interlocked.Increment(ref _nextId);
21 return new TraceSource(typeof(T).Name);
22 }
23
24 public static TraceSource TraceSource { get { return _traceSource.Value; } }
25
26 public static IDisposable Subscribe() {
27
28 throw new NotImplementedException();
29 }
13 30
14 #if NETFX_TRACE_BUG 31 #if NETFX_TRACE_BUG
15 readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>(); 32 readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>();
16 #endif 33 #endif
17 34