예제 #1
0
 /// <summary>
 /// Create a new instance of <see cref="LogEventId"/>.
 /// </summary>
 /// <param name="eventId"></param>
 /// <param name="id"></param>
 /// <param name="name"></param>
 internal LogEventId(LogEventId eventId, string id, string name)
 {
     Id             = id;
     Name           = name;
     TraceId        = eventId.TraceId;
     Timestamp      = Now();
     _parentEventId = eventId;
 }
예제 #2
0
 /// <summary>
 /// Create a new instance of <see cref="LogEventId"/>.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="traceId"></param>
 internal LogEventId(string id, string name, string traceId)
 {
     Id             = id;
     Name           = name;
     TraceId        = traceId;
     Timestamp      = Now();
     _parentEventId = default;
 }
예제 #3
0
 public ManuallyLogEventDescriptor(LogEventId eventId, LogEventLevel level, Exception exception, string messageTemplate,
                                   ILogCallerInfo callerInfo, LogEventContext context = null, params object[] messageTemplateParameters)
 {
     EventId                   = eventId;
     Level                     = level;
     Exception                 = exception;
     MessageTemplate           = messageTemplate;
     CallerInfo                = callerInfo;
     Context                   = context;
     MessageTemplateParameters = messageTemplateParameters;
 }
예제 #4
0
        private static LogEventId CreateOrUpdateCurrentEventId(string id, string name, string traceId)
        {
            /*
             * 1、 当 LogEventId.Current 为空的时候(此时 NeedUpdateCurrentValue 为 true),将压入一个新的 LogEventId 实例作为 root,NeedUpdateCurrentValue 标记为 false,并返回
             * 2、 当 LogEventId.Current 不为空,则取出 Current,并以之作为 Parent,生成一个新的 LogEventId 实例,不压如入 Current,返回
             * 3、 当 BeginScope,则将 NeedUpdateCurrentValue 标记为 true;
             *         在下一次 TouchCurrentEventId 时将第一个 eventId 压入,将原 current 作为 Parent
             */

            name ??= string.Empty;
            if (string.IsNullOrWhiteSpace(id))
            {
                id = Guid.NewGuid().ToString();
            }

            var eventIdMaybe    = Optional.From(LogEventId.Current);
            var realTraceId     = MakeRealTraceId(Optional.From(eventIdMaybe.Value?.TraceId), traceId);
            var businessTraceId = MakeBusinessTraceId(Optional.From(eventIdMaybe.Value?.BusinessTraceId), traceId, realTraceId);

            LogEventId instance;

            if (eventIdMaybe.HasValue)
            {
                instance = new LogEventId(eventIdMaybe.Value, id, name)
                {
                    BusinessTraceId = businessTraceId
                };
            }
            else
            {
                instance = new LogEventId(id, name, realTraceId)
                {
                    BusinessTraceId = businessTraceId
                };
            }

            if (LogEventId.NeedUpdateCurrentValue)
            {
                LogEventId.Current = instance;
                LogEventId.NeedUpdateCurrentValue = false;
            }

            return(instance);
        }