/// <summary> /// Fills the exit information. /// </summary> /// <param name="step">The piece.</param> /// <param name="exceptionKey">The exception key.</param> /// <param name="exitStamp">The exit stamp.</param> private static void Exit(ApiTraceStep step, Guid?exceptionKey, DateTime?exitStamp = null) { if (step != null) { step.ExceptionKey = exceptionKey; step.ExitStamp = exitStamp ?? DateTime.UtcNow; _current = step.Parent; } if (_root != null && !_root.ExceptionKey.HasValue) { _root.ExceptionKey = exceptionKey; } }
///// <summary> ///// Enters the specified method call information. ///// </summary> ///// <param name="methodCallInfo">The method call information.</param> ///// <param name="entryStamp">The entry stamp.</param> ///// <param name="setNameAsMajor">if set to <c>true</c> [set name as major].</param> //internal static void Enter(MethodCallInfo methodCallInfo, DateTime? entryStamp = null, bool setNameAsMajor = false) //{ // Enter(methodCallInfo.ToTraceLog(_current, entryStamp ?? DateTime.UtcNow), setNameAsMajor); //} /// <summary> /// Enters the specified trace log. /// </summary> /// <param name="traceStep">The trace step.</param> /// <param name="setNameAsMajor">The set name as major.</param> internal static void Enter(ApiTraceStep traceStep, bool setNameAsMajor = false) { if (traceStep != null) { if (_root != null) { traceStep.Parent = _current; _current.InnerTraces.Add(traceStep); _current = traceStep; if (setNameAsMajor && !string.IsNullOrWhiteSpace(_current.MethodFullName)) { _root.MethodFullName = _current.MethodFullName; } } } }
/// <summary> /// APIs the trace log to string. /// </summary> /// <param name="builder">The builder.</param> /// <param name="log">The log.</param> /// <param name="level">The level.</param> /// <returns>System.String.</returns> private static void ApiTraceLogToString(StringBuilder builder, ApiTraceStep log, int level) { if (builder != null && log != null) { builder.AppendIndent(level); builder.AppendLineWithFormat("Entry: {0}", log.EntryStamp.ToFullDateTimeString()); builder.AppendIndent(level); builder.AppendLineWithFormat("Exit: {0}", log.ExitStamp.ToFullDateTimeString()); builder.AppendIndent(level); builder.AppendLineWithFormat("Exception Key: {0}", log.ExceptionKey); builder.AppendIndent(level); foreach (var one in log.InnerTraces) { builder.AppendLineWithFormat("Inner trace: "); ApiTraceLogToString(builder, one, level + 1); } } }
/// <summary> /// Initializes the specified trace identifier. /// </summary> /// <param name="traceId">The trace identifier.</param> /// <param name="traceSequence">The trace sequence.</param> /// <param name="entryStamp">The entry stamp.</param> /// <param name="methodName">Name of the method.</param> public static void Initialize(string traceId, int?traceSequence, DateTime?entryStamp = null, [CallerMemberName] string methodName = null) { if (!string.IsNullOrWhiteSpace(traceId)) { if (!entryStamp.HasValue) { entryStamp = DateTime.UtcNow; } _root = new ApiTraceLog() { TraceId = traceId, TraceSequence = traceSequence.HasValue ? (traceSequence.Value + 1) : 0, EntryStamp = entryStamp }; var current = new ApiTraceStep(_root, methodName, entryStamp); _root.InnerTraces.Add(current); _current = current; } }
/// <summary> /// Disposes this instance. /// </summary> public static void Dispose() { _current = null; _root = null; }