Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/TextListenerBase.cs @ 48:d9d794b61bb9 interactive logger
Interactive tracing
Improved working with tracing contexts
author | cin |
---|---|
date | Fri, 18 Apr 2014 12:34:45 +0400 |
parents | b181f7bcb259 |
children | 4c0e5ef99986 |
comparison
equal
deleted
inserted
replaced
47:b181f7bcb259 | 48:d9d794b61bb9 |
---|---|
8 | 8 |
9 readonly Dictionary<object, Action> m_subscriptions = new Dictionary<object, Action>(); | 9 readonly Dictionary<object, Action> m_subscriptions = new Dictionary<object, Action>(); |
10 readonly LogicalOperation m_boundOperation; | 10 readonly LogicalOperation m_boundOperation; |
11 readonly int m_baseIndent; | 11 readonly int m_baseIndent; |
12 | 12 |
13 protected TextListenerBase(bool local) { | 13 protected TextListenerBase(bool global) { |
14 Register(this); | 14 Register(this); |
15 if (local) { | 15 if (!global) { |
16 m_boundOperation = TraceContext.Current.CurrentOperation; | 16 m_boundOperation = TraceContext.Current.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 |
34 | 34 |
35 lock (m_subscriptions) { | 35 lock (m_subscriptions) { |
36 AssertNotDisposed(); | 36 AssertNotDisposed(); |
37 | 37 |
38 var formatter = GetService<IEventTextFormatter<TEvent>>(); | 38 var formatter = GetService<IEventTextFormatter<TEvent>>(); |
39 var channelName = channel.Name; | |
39 | 40 |
40 EventHandler<ValueEventArgs<TEvent>> handler = (sender, args) => { | 41 EventHandler<ValueEventArgs<TEvent>> handler = (sender, args) => { |
41 TraceContext context = (TraceContext)sender; | 42 TraceContext context = (TraceContext)sender; |
42 var text = formatter.Format(context, args.Value); | 43 var text = formatter.Format(context, args.Value); |
43 text.indent -= m_baseIndent; | 44 text.indent -= m_baseIndent; |
44 | 45 |
45 if (IsRelated(context.CurrentOperation)) | 46 if (IsRelated(context.CurrentOperation)) |
46 WriteEntry(context, text); | 47 WriteEntry(context, text, channelName); |
47 }; | 48 }; |
48 | 49 |
49 if (m_subscriptions.ContainsKey(channel)) | 50 if (m_subscriptions.ContainsKey(channel)) |
50 return; | 51 return; |
51 | 52 |
96 /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда | 97 /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда |
97 /// данный метод вызывается уже после освобождения ообъекта методом <see cref="Dispose()"/>. | 98 /// данный метод вызывается уже после освобождения ообъекта методом <see cref="Dispose()"/>. |
98 /// </remarks> | 99 /// </remarks> |
99 /// <param name="context">Контекст трассировки.</param> | 100 /// <param name="context">Контекст трассировки.</param> |
100 /// <param name="text">Текст сообщения.</param> | 101 /// <param name="text">Текст сообщения.</param> |
101 protected abstract void WriteEntry(TraceContext context, EventText text); | 102 protected abstract void WriteEntry(TraceContext context, EventText text, string channel); |
102 | 103 |
103 public EventText Format(TraceContext context, object data) { | 104 public EventText Format(TraceContext context, object data) { |
104 return new EventText { | 105 return new EventText { |
105 indent = context.CurrentOperation.Level, | 106 indent = context.CurrentOperation.Level, |
106 content = data.ToString() | 107 content = data.ToString() |