コード例 #1
0
        /// <summary>
        /// Converts the API trace log.
        /// </summary>
        /// <param name="apiTraceLog">The API trace log.</param>
        /// <returns>ApiTraceLog.</returns>
        private static ApiTraceLog ConvertApiTraceLog(RuntimeApiTraceLog apiTraceLog)
        {
            if (apiTraceLog != null)
            {
                var result = new ApiTraceLog
                {
                    EntryStamp = apiTraceLog.EntryStamp,
                    Exception = apiTraceLog.Exception,
                    ExitStamp = apiTraceLog.ExitStamp,
                    MethodFullName = apiTraceLog.MethodFullName,
                    TraceId = TraceId,
                    MethodParameters = apiTraceLog.MethodParameters
                };

                foreach (var one in apiTraceLog.Children)
                {
                    result.InnerTraces.Add(ConvertApiTraceLogPiece(one));
                }

                return result;
            }

            return null;
        }
コード例 #2
0
 /// <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))
     {
         _root = new ApiTraceLog(entryStamp: entryStamp)
         {
             TraceId = traceId,
             TraceSequence = traceSequence.HasValue ? (traceSequence.Value + 1) : 0
         };
         var current = new ApiTraceLogPiece(_root, methodName, entryStamp);
         _root.InnerTraces.Add(current);
         _current = current;
     }
 }
コード例 #3
0
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 public static void Dispose()
 {
     _current = null;
     _root = null;
 }
コード例 #4
0
        /// <summary>
        /// APIs the trace log to string.
        /// </summary>
        /// <param name="log">The log.</param>
        /// <param name="level">The level.</param>
        /// <returns>System.String.</returns>
        private static string ApiTraceLogToString(ApiTraceLog log, int level)
        {
            StringBuilder builder = new StringBuilder();

            if (log != null)
            {
                builder.AppendIndent(' ', 2 * (level + 1));
                builder.AppendLineWithFormat("Trace ID: {0}", log.TraceId);

                builder.AppendIndent(' ', 2 * (level + 1));
                builder.AppendLineWithFormat("Entry: {0}", log.EntryStamp.ToFullDateTimeString());
                builder.AppendIndent(' ', 2 * (level + 1));
                builder.AppendLineWithFormat("Exit: {0}", log.ExitStamp.ToFullDateTimeString());
                builder.AppendIndent(' ', 2 * (level + 1));
                builder.AppendLineWithFormat("Parameters: {0}", log.MethodParameters.ToJson());
                builder.AppendIndent(' ', 2 * (level + 1));
                builder.AppendLineWithFormat("Exception: {0}", log.Exception == null ? "NA" : log.Exception.ToJson());
                builder.AppendIndent(' ', 2 * (level + 1));
                foreach (var one in log.InnerTraces)
                {
                    builder.AppendLineWithFormat("Inner trace: {0}", ApiTraceLogToString(one, level + 1));
                }
            }

            return builder.ToString();
        }