comparison Implab/Diagnostics/TextListenerBase.cs @ 92:4c0e5ef99986 v2

rewritten tracing
author cin
date Wed, 22 Oct 2014 18:37:56 +0400
parents d9d794b61bb9
children
comparison
equal deleted inserted replaced
91:cdaaf4792c22 92:4c0e5ef99986
11 readonly int m_baseIndent; 11 readonly int m_baseIndent;
12 12
13 protected TextListenerBase(bool global) { 13 protected TextListenerBase(bool global) {
14 Register(this); 14 Register(this);
15 if (!global) { 15 if (!global) {
16 m_boundOperation = TraceContext.Current.CurrentOperation; 16 m_boundOperation = TraceContext.Instance.CurrentOperation;
17 m_baseIndent = Math.Max(0, m_boundOperation.Level - 1); 17 m_baseIndent = Math.Max(0, m_boundOperation.Level - 1);
18 } 18 }
19 } 19 }
20 20
21 public void Subscribe(Type eventType) { 21 public void Subscribe(Type eventType) {
36 AssertNotDisposed(); 36 AssertNotDisposed();
37 37
38 var formatter = GetService<IEventTextFormatter<TEvent>>(); 38 var formatter = GetService<IEventTextFormatter<TEvent>>();
39 var channelName = channel.Name; 39 var channelName = channel.Name;
40 40
41 EventHandler<ValueEventArgs<TEvent>> handler = (sender, args) => { 41 EventHandler<LogEventArgs<TEvent>> handler = (sender, args) => {
42 TraceContext context = (TraceContext)sender; 42 var text = formatter.Format(args, args.Value);
43 var text = formatter.Format(context, args.Value);
44 text.indent -= m_baseIndent; 43 text.indent -= m_baseIndent;
45 44
46 if (IsRelated(context.CurrentOperation)) 45 if (IsRelated(args.Operation))
47 WriteEntry(context, text, channelName); 46 WriteEntry(args, text, channelName);
48 }; 47 };
49 48
50 if (m_subscriptions.ContainsKey(channel)) 49 if (m_subscriptions.ContainsKey(channel))
51 return; 50 return;
52 51
95 /// </summary> 94 /// </summary>
96 /// <remarks> 95 /// <remarks>
97 /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда 96 /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда
98 /// данный метод вызывается уже после освобождения ообъекта методом <see cref="Dispose()"/>. 97 /// данный метод вызывается уже после освобождения ообъекта методом <see cref="Dispose()"/>.
99 /// </remarks> 98 /// </remarks>
100 /// <param name="context">Контекст трассировки.</param>
101 /// <param name="text">Текст сообщения.</param> 99 /// <param name="text">Текст сообщения.</param>
102 protected abstract void WriteEntry(TraceContext context, EventText text, string channel); 100 /// <param name = "channel"></param>
101 protected abstract void WriteEntry(LogEventArgs args, EventText text, string channel);
103 102
104 public EventText Format(TraceContext context, object data) { 103 public EventText Format(LogEventArgs args, object data) {
105 return new EventText { 104 return new EventText {
106 indent = context.CurrentOperation.Level, 105 indent = args.Operation.Level,
107 content = data.ToString() 106 content = data.ToString()
108 }; 107 };
109 } 108 }
110 109
111 public EventText Format(TraceContext context, TraceEvent data) { 110 public EventText Format(LogEventArgs args, TraceEvent data) {
112 var level = context.CurrentOperation.Level; 111 var level = args.Operation.Level;
113 if (data.EventType == TraceEventType.OperationCompleted || data.EventType == TraceEventType.OperationStarted) 112 if (data.EventType == TraceEventType.OperationCompleted || data.EventType == TraceEventType.OperationStarted)
114 level--; 113 level--;
115 114
116 return new EventText { 115 return new EventText {
117 indent = level, 116 indent = level,