2

I log application tracing informations using Jaeger.

Do I need to use other log package again?

4

2 回答 2

2

OpenTracing 是分布式跟踪的框架。因此,它更多的是关于性能监控和可观察性而不是日志记录(NLog 是关于什么的)。

OpenTracing 允许您手动检测代码以生成具有相关跨度的跟踪,其中包含有关应用程序中代码执行的信息。这包括用错误和任意键和值注释跨度,您可以使用它们来代替日志记录。但是,这与专用结构化日志记录不同。

于 2019-01-15T13:32:19.893 回答
0

可以使用此目标将 LogEvents 从 NLog 转发到 OpenTracing:

    [Target("OpenTracing")]
    public class OpenTracingTarget : TargetWithContext
    {
        private readonly OpenTracing.ITracer _tracer;

        public bool SetTagErrorOnException { get; set; }

        public OpenTracingTarget()
            :this(null)
        {
        }

        public OpenTracingTarget(OpenTracing.ITracer tracer)
        {
            _tracer = tracer ?? OpenTracing.Util.GlobalTracer.Instance;
            ContextProperties.Add(new TargetPropertyWithContext("component", "${logger}"));
            ContextProperties.Add(new TargetPropertyWithContext("level", "${level}"));
            ContextProperties.Add(new TargetPropertyWithContext("message", "${message}"));
            ContextProperties.Add(new TargetPropertyWithContext("event", "${event-properties:EventId_Name}") { IncludeEmptyValue = false });
            ContextProperties.Add(new TargetPropertyWithContext("eventid", "${event-properties:EventId_Id}") { IncludeEmptyValue = false });
        }

        protected override void Write(LogEventInfo logEvent)
        {
            var span = _tracer.ActiveSpan;
            if (span == null)
                return;

            if (SetTagErrorOnException && logEvent.Exception != null)
            {
                span.SetTag(OpenTracing.Tag.Tags.Error, true);
            }

            var fields = GetAllProperties(logEvent);
            if (logEvent.Exception != null)
            {
                fields[OpenTracing.LogFields.ErrorKind] = logEvent.Exception.GetType().ToString();
                fields[OpenTracing.LogFields.ErrorObject] = logEvent.Exception;
            }

            span.Log(fields);
        }
    }
于 2021-05-16T08:57:16.923 回答