using System.Diagnostics; using Serilog.Core; using Serilog.Events; namespace Deal.Api.Logging; internal sealed class TraceContextEnricher : ILogEventEnricher { void ILogEventEnricher.Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { Activity? activity = Activity.Current; if (activity is null) { return; } logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("TraceId", activity.TraceId.ToString())); logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("SpanId", activity.SpanId.ToString())); } }