diff --git a/Benchmark/Benchmark.csproj b/Benchmark/Benchmark.csproj
index d1db396..41dd179 100644
--- a/Benchmark/Benchmark.csproj
+++ b/Benchmark/Benchmark.csproj
@@ -2,7 +2,7 @@
Exe
- net48;net6.0
+ net48;net8.0
Latest
Debug;Release;Test;Test
diff --git a/NLog.Targets.OpenTelemetryProtocol.Test/NLog.Targets.OpenTelemetryProtocol.Test.csproj b/NLog.Targets.OpenTelemetryProtocol.Test/NLog.Targets.OpenTelemetryProtocol.Test.csproj
index 05b6672..0fc6206 100644
--- a/NLog.Targets.OpenTelemetryProtocol.Test/NLog.Targets.OpenTelemetryProtocol.Test.csproj
+++ b/NLog.Targets.OpenTelemetryProtocol.Test/NLog.Targets.OpenTelemetryProtocol.Test.csproj
@@ -1,20 +1,20 @@
-
- Exe
- net6.0
- Latest
- Debug;Release;Test;Test
-
+
+ Exe
+ net8.0
+ Latest
+ Debug;Release;Test
+
-
-
-
+
+
+
-
-
- Always
-
-
+
+
+ Always
+
+
diff --git a/NLog.Targets.OpenTelemetryProtocol.Test/Program.cs b/NLog.Targets.OpenTelemetryProtocol.Test/Program.cs
index 2ca6825..64b72af 100644
--- a/NLog.Targets.OpenTelemetryProtocol.Test/Program.cs
+++ b/NLog.Targets.OpenTelemetryProtocol.Test/Program.cs
@@ -11,6 +11,8 @@ public static void Main()
var message = "testing";
+ using var currentActivity = new System.Diagnostics.Activity("Hello World").Start();
+
logger.Fatal("message: {messageField}", message);
Thread.Sleep(10000);
diff --git a/NLog.Targets.OpenTelemetryProtocol/ActivityExtensions.cs b/NLog.Targets.OpenTelemetryProtocol/ActivityExtensions.cs
new file mode 100644
index 0000000..8b3656d
--- /dev/null
+++ b/NLog.Targets.OpenTelemetryProtocol/ActivityExtensions.cs
@@ -0,0 +1,52 @@
+using System.Diagnostics;
+
+namespace NLog.Targets.OpenTelemetryProtocol
+{
+ ///
+ /// Formats elements of for inclusion in log events. Non-W3C-format activities are
+ /// ignored (Seq does not support the older Microsoft-proprietary hierarchical activity id format).
+ ///
+ internal static class ActivityExtensions
+ {
+ private static readonly System.Diagnostics.ActivitySpanId EmptySpanId = default(System.Diagnostics.ActivitySpanId);
+ private static readonly System.Diagnostics.ActivityTraceId EmptyTraceId = default(System.Diagnostics.ActivityTraceId);
+
+ public static string GetSpanId(this Activity activity)
+ {
+ return activity.IdFormat == ActivityIdFormat.W3C ?
+ SpanIdToHexString(activity.SpanId) :
+ string.Empty;
+ }
+
+ public static string GetTraceId(this Activity activity)
+ {
+ return activity.IdFormat == ActivityIdFormat.W3C ?
+ TraceIdToHexString(activity.TraceId) :
+ string.Empty;
+ }
+
+ private static string SpanIdToHexString(ActivitySpanId spanId)
+ {
+ if (EmptySpanId.Equals(spanId))
+ return string.Empty;
+
+ var spanHexString = spanId.ToHexString();
+ if (ReferenceEquals(spanHexString, EmptySpanId.ToHexString()))
+ return string.Empty;
+
+ return spanHexString;
+ }
+
+ private static string TraceIdToHexString(ActivityTraceId traceId)
+ {
+ if (EmptyTraceId.Equals(traceId))
+ return string.Empty;
+
+ var traceHexString = traceId.ToHexString();
+ if (ReferenceEquals(traceHexString, EmptyTraceId.ToHexString()))
+ return string.Empty;
+
+ return traceHexString;
+ }
+ }
+}
diff --git a/NLog.Targets.OpenTelemetryProtocol/NLog.Targets.OpenTelemetryProtocol.csproj b/NLog.Targets.OpenTelemetryProtocol/NLog.Targets.OpenTelemetryProtocol.csproj
index a32699b..1e43fcf 100644
--- a/NLog.Targets.OpenTelemetryProtocol/NLog.Targets.OpenTelemetryProtocol.csproj
+++ b/NLog.Targets.OpenTelemetryProtocol/NLog.Targets.OpenTelemetryProtocol.csproj
@@ -26,7 +26,7 @@
-
+
diff --git a/NLog.Targets.OpenTelemetryProtocol/OpenTelemetryEventListener.cs b/NLog.Targets.OpenTelemetryProtocol/OpenTelemetryEventListener.cs
index d83dfa9..c745cca 100644
--- a/NLog.Targets.OpenTelemetryProtocol/OpenTelemetryEventListener.cs
+++ b/NLog.Targets.OpenTelemetryProtocol/OpenTelemetryEventListener.cs
@@ -30,7 +30,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
}
}
- private void WriteEvent(EventLevel eventLevel, string? eventMessage, IReadOnlyList