Mercurial > pub > ImplabNet
diff Implab/Diagnostics/Trace.cs @ 255:b00441e04738 v3
Adde workaround to the behaviour of the logical operations stack in conjuction
with async/await methods
author | cin |
---|---|
date | Wed, 04 Apr 2018 15:38:48 +0300 |
parents | 34df34841225 |
children | f07be402ab02 |
line wrap: on
line diff
--- a/Implab/Diagnostics/Trace.cs Mon Feb 12 17:03:49 2018 +0300 +++ b/Implab/Diagnostics/Trace.cs Wed Apr 04 15:38:48 2018 +0300 @@ -3,21 +3,21 @@ using System.Diagnostics; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Implab.Diagnostics { public static class Trace<T> { - readonly static TraceSource _traceSource = new TraceSource(typeof(T).Name); - - public static TraceSource TraceSource { - get { return _traceSource; } - } - + public static TraceSource TraceSource { get; } = new TraceSource(typeof(T).Name); + +#if NETFX_TRACE_BUG + readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>(); +#endif + /// <summary> /// Starts the logical operation nested to the current operation nested to the current one. /// </summary> - [Conditional("TRACE")] public static void StartLogicalOperation() { Trace.CorrelationManager.StartLogicalOperation(); @@ -27,15 +27,20 @@ /// Starts the logical operation with the specified name, this name is usefull in logs. /// </summary> /// <param name="name">Name.</param> - [Conditional("TRACE")] - public static void StartLogicalOperation(string name) { +#if NETFX_TRACE_BUG + public static void StartLogicalOperation(object name) { + m_currentOperation.Value = name; Trace.CorrelationManager.StartLogicalOperation(name); } +#else + public static void StartLogicalOperation(object name) { + Trace.CorrelationManager.StartLogicalOperation(name); + } +#endif /// <summary> /// Ends the logical operation and restores the previous one. /// </summary> - [Conditional("TRACE")] public static void StopLogicalOperation() { Trace.CorrelationManager.StopLogicalOperation(); } @@ -120,7 +125,7 @@ public static LogicalOperationScope LogicalOperation(string name) { var operation = new LogicalOperation(name); TraceSource.TraceData(TraceEventType.Information, TraceEventCodes.StartLogicalOperation, operation); - Trace.CorrelationManager.StartLogicalOperation(operation); + StartLogicalOperation(operation); return new LogicalOperationScope(TraceSource, operation); } }