Пример #1
0
        public static TraceInfoBuilder ToTraceInfoBuilder(this HttpContext context, string id = null, Exception exception = null)
        {
            var    request       = context.Request;
            var    parentTrackId = request.Headers["parent-track-id"].FirstOrDefault();
            string parentid      = null;

            if (string.IsNullOrEmpty(id))
            {
                id = request.Headers["chain-id"].FirstOrDefault();
            }
            else
            {
                parentid = request.Headers["chain-id"].FirstOrDefault();
            }


            var trackId     = request.Headers["track-id"].FirstOrDefault();
            var trackTime   = request.Headers["track-time"].FirstOrDefault();
            var elapsedTime = (DateTime.Now.Ticks - Convert.ToInt64(trackTime)) / 1000000;//转换为ms


            var traceInfoBuilder = TraceInfoBuilder.CreateBuilder().BuildTraceInfo(id).ParentId(parentid).TrackId(trackId, parentTrackId)
                                   .HttpContext(context).ElapsedTime(elapsedTime).Log(LogLevel.Trace, "", exception);

            return(traceInfoBuilder);
        }
Пример #2
0
 public TraceInfoBuilder BuildFromTraceInfoBuilder(TraceInfoBuilder traceInfoBuilder, bool isAll = false)
 {
     if (traceInfoBuilder == null)
     {
         throw new ArgumentException($"traceInfoBuilder not null");
     }
     return(BuildFromTraceInfo(traceInfoBuilder.Build(), isAll));
 }