Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/TextListenerBase.cs @ 50:f8cbe84cfdb1
Слияние с interactive logger
| author | cin |
|---|---|
| date | Fri, 18 Apr 2014 12:37:48 +0400 |
| parents | d9d794b61bb9 |
| children | 4c0e5ef99986 |
comparison
equal
deleted
inserted
replaced
| 44:e5ec543feee3 | 50:f8cbe84cfdb1 |
|---|---|
| 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 |
| 87 subscription(); | 88 subscription(); |
| 88 m_subscriptions.Clear(); | 89 m_subscriptions.Clear(); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 protected abstract void WriteEntry(TraceContext context, EventText text); | 93 /// <summary> |
| 94 /// Вызывается для записи текста сообщения, в журнал. | |
| 95 /// </summary> | |
| 96 /// <remarks> | |
| 97 /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда | |
| 98 /// данный метод вызывается уже после освобождения ообъекта методом <see cref="Dispose()"/>. | |
| 99 /// </remarks> | |
| 100 /// <param name="context">Контекст трассировки.</param> | |
| 101 /// <param name="text">Текст сообщения.</param> | |
| 102 protected abstract void WriteEntry(TraceContext context, EventText text, string channel); | |
| 93 | 103 |
| 94 public EventText Format(TraceContext context, object data) { | 104 public EventText Format(TraceContext context, object data) { |
| 95 return new EventText { | 105 return new EventText { |
| 96 indent = context.CurrentOperation.Level, | 106 indent = context.CurrentOperation.Level, |
| 97 content = data.ToString() | 107 content = data.ToString() |
| 108 content = data.ToString() | 118 content = data.ToString() |
| 109 }; | 119 }; |
| 110 } | 120 } |
| 111 | 121 |
| 112 protected override void Dispose(bool disposing) { | 122 protected override void Dispose(bool disposing) { |
| 123 base.Dispose(disposing); | |
| 113 if (disposing) { | 124 if (disposing) { |
| 114 UnsubscribeAll(); | 125 UnsubscribeAll(); |
| 115 } | 126 } |
| 116 base.Dispose(disposing); | |
| 117 } | 127 } |
| 118 } | 128 } |
| 119 } | 129 } |
