@@ -116,7 +116,7 namespace Implab.Diagnostics { | |||
|
116 | 116 | /// </summary> |
|
117 | 117 | /// <returns>Копия текущего контекста трассировки.</returns> |
|
118 | 118 | public static TraceContext Snapshot() { |
|
119 | return _current == null ? new TraceContext() : new TraceContext(_current); | |
|
119 | return _current == null ? new TraceContext() : new TraceContext(_current,false); | |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /// <summary> |
@@ -131,7 +131,8 namespace Implab.Diagnostics { | |||
|
131 | 131 | try { |
|
132 | 132 | action(); |
|
133 | 133 | } finally { |
|
134 |
_current |
|
|
134 | if(_current != null) | |
|
135 | _current.EndAllOperations(); | |
|
135 | 136 | _current = old; |
|
136 | 137 | } |
|
137 | 138 | } |
@@ -197,6 +198,32 namespace Implab.Diagnostics { | |||
|
197 | 198 | } |
|
198 | 199 | |
|
199 | 200 | /// <summary> |
|
201 | /// Создает копию контекста и возвращается на предыдущую операцию в текущем контексте, это позволяет начать операцию в одном потоке, а завершить - в другом. | |
|
202 | /// </summary> | |
|
203 | /// <returns>Контекст трассировки, который можно присоединить к другому потоку.</returns> | |
|
204 | public TraceContext DetachLogicalOperation() { | |
|
205 | if (m_bound == m_currentOperation) { | |
|
206 | return new TraceContext(); | |
|
207 | } else { | |
|
208 | var detached = new TraceContext(this, true); | |
|
209 | m_currentOperation = m_currentOperation.Parent; | |
|
210 | return detached; | |
|
211 | } | |
|
212 | } | |
|
213 | ||
|
214 | public void BindLogicalOperationToPromise(IPromiseBase promise) { | |
|
215 | Safe.ArgumentNotNull(promise, "promise"); | |
|
216 | ||
|
217 | var ctx = DetachLogicalOperation(); | |
|
218 | promise.Finally(() => { | |
|
219 | var old = _current; | |
|
220 | TraceContext.Attach(ctx); | |
|
221 | TraceContext.Current.EndLogicalOperation(); | |
|
222 | _current = old; | |
|
223 | }); | |
|
224 | } | |
|
225 | ||
|
226 | /// <summary> | |
|
200 | 227 | /// Заврешает все начатые в этом контексте операции |
|
201 | 228 | /// </summary> |
|
202 | 229 | public void EndAllOperations() { |
@@ -21,7 +21,10 namespace Implab.Diagnostics { | |||
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | public override string ToString() { |
|
24 | return String.Format("{0}: {1}", EventType, Message); | |
|
24 | if (EventType == TraceEventType.Information) | |
|
25 | return Message; | |
|
26 | else | |
|
27 | return String.Format("{0}: {1}", EventType, Message); | |
|
25 | 28 | } |
|
26 | 29 | |
|
27 | 30 | public static TraceEvent Create(TraceEventType type, string format, params object[] args) { |
@@ -28,6 +28,11 namespace Implab.Diagnostics { | |||
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | [Conditional("TRACE")] |
|
31 | public static void BindLogicalOperationToPromise(IPromiseBase promise) { | |
|
32 | TraceContext.Current.BindLogicalOperationToPromise(promise); | |
|
33 | } | |
|
34 | ||
|
35 | [Conditional("TRACE")] | |
|
31 | 36 | public static void TraceInformation(string format, params object[] arguments) { |
|
32 | 37 | LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments)); |
|
33 | 38 | } |
General Comments 0
You need to be logged in to leave comments.
Login now