Mercurial > pub > ImplabNet
changeset 52:edf0bc558596
improved trace system
author | cin |
---|---|
date | Mon, 05 May 2014 07:35:48 +0400 |
parents | 2c332a9c64c0 |
children | 104ce3fe5c46 |
files | Implab/Diagnostics/TraceContext.cs Implab/Diagnostics/TraceEvent.cs Implab/Diagnostics/TraceLog.cs |
diffstat | 3 files changed, 38 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Implab/Diagnostics/TraceContext.cs Sat Apr 26 23:36:00 2014 +0400 +++ b/Implab/Diagnostics/TraceContext.cs Mon May 05 07:35:48 2014 +0400 @@ -116,7 +116,7 @@ /// </summary> /// <returns>Копия текущего контекста трассировки.</returns> public static TraceContext Snapshot() { - return _current == null ? new TraceContext() : new TraceContext(_current); + return _current == null ? new TraceContext() : new TraceContext(_current,false); } /// <summary> @@ -131,7 +131,8 @@ try { action(); } finally { - _current.EndAllOperations(); + if(_current != null) + _current.EndAllOperations(); _current = old; } } @@ -197,6 +198,32 @@ } /// <summary> + /// Создает копию контекста и возвращается на предыдущую операцию в текущем контексте, это позволяет начать операцию в одном потоке, а завершить - в другом. + /// </summary> + /// <returns>Контекст трассировки, который можно присоединить к другому потоку.</returns> + public TraceContext DetachLogicalOperation() { + if (m_bound == m_currentOperation) { + return new TraceContext(); + } else { + var detached = new TraceContext(this, true); + m_currentOperation = m_currentOperation.Parent; + return detached; + } + } + + public void BindLogicalOperationToPromise(IPromiseBase promise) { + Safe.ArgumentNotNull(promise, "promise"); + + var ctx = DetachLogicalOperation(); + promise.Finally(() => { + var old = _current; + TraceContext.Attach(ctx); + TraceContext.Current.EndLogicalOperation(); + _current = old; + }); + } + + /// <summary> /// Заврешает все начатые в этом контексте операции /// </summary> public void EndAllOperations() {
--- a/Implab/Diagnostics/TraceEvent.cs Sat Apr 26 23:36:00 2014 +0400 +++ b/Implab/Diagnostics/TraceEvent.cs Mon May 05 07:35:48 2014 +0400 @@ -21,7 +21,10 @@ } public override string ToString() { - return String.Format("{0}: {1}", EventType, Message); + if (EventType == TraceEventType.Information) + return Message; + else + return String.Format("{0}: {1}", EventType, Message); } public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
--- a/Implab/Diagnostics/TraceLog.cs Sat Apr 26 23:36:00 2014 +0400 +++ b/Implab/Diagnostics/TraceLog.cs Mon May 05 07:35:48 2014 +0400 @@ -28,6 +28,11 @@ } [Conditional("TRACE")] + public static void BindLogicalOperationToPromise(IPromiseBase promise) { + TraceContext.Current.BindLogicalOperationToPromise(promise); + } + + [Conditional("TRACE")] public static void TraceInformation(string format, params object[] arguments) { LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments)); }