diff --git a/src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs b/src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs index e7ab9ef..e5e2fad 100644 --- a/src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs +++ b/src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs @@ -104,6 +104,18 @@ private LogEntry CreateLogEntry(LogEvent evnt, StringWriter writer) HandleSpecialProperty(log, property.Key, property.Value); } + if (_sinkOptions.UseLogCorrelation) + { + if (evnt.TraceId.ToString() is { Length: > 0 } traceId) + { + log.Trace = $"projects/{_projectId}/traces/{traceId}"; + } + if (evnt.SpanId?.ToString() is { Length: > 0 } spanId) + { + log.SpanId = spanId; + } + } + if (_serviceContext != null) jsonPayload.Fields.Add("serviceContext", Value.ForStruct(_serviceContext)); @@ -119,12 +131,6 @@ private void HandleSpecialProperty(LogEntry log, string key, LogEventPropertyVal if (_sinkOptions.UseLogCorrelation) { - if (key.Equals("TraceId", StringComparison.OrdinalIgnoreCase)) - log.Trace = $"projects/{_projectId}/traces/{GetString(value)}"; - - if (key.Equals("SpanId", StringComparison.OrdinalIgnoreCase)) - log.SpanId = GetString(value); - if (key.Equals("TraceSampled", StringComparison.OrdinalIgnoreCase)) log.TraceSampled = GetBoolean(value); } diff --git a/src/Serilog.Sinks.GoogleCloudLogging/Serilog.Sinks.GoogleCloudLogging.csproj b/src/Serilog.Sinks.GoogleCloudLogging/Serilog.Sinks.GoogleCloudLogging.csproj index c2e8fcc..ac7eb9b 100644 --- a/src/Serilog.Sinks.GoogleCloudLogging/Serilog.Sinks.GoogleCloudLogging.csproj +++ b/src/Serilog.Sinks.GoogleCloudLogging/Serilog.Sinks.GoogleCloudLogging.csproj @@ -18,7 +18,7 @@ true snupkg true - net6.0;net5.0;netstandard2.1 + net8.0;net6.0;netstandard2.1 latest enable @@ -29,14 +29,15 @@ - + all runtime; build; native; contentfiles; analyzers - - - + + + + diff --git a/src/TestWeb/TestWeb.csproj b/src/TestWeb/TestWeb.csproj index f6bee1d..e912a38 100644 --- a/src/TestWeb/TestWeb.csproj +++ b/src/TestWeb/TestWeb.csproj @@ -1,15 +1,15 @@  - net6.0 + net8.0 default false - - - + + +