Skip to content

Commit

Permalink
Fixed IncludeActivityIdsWithBeginScope for NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Dec 29, 2023
1 parent cfe3e59 commit 7caa533
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/NLog.Extensions.Logging/Logging/ActivityExtensions.cs
@@ -1,4 +1,4 @@
#if NET6_0
#if NET5_0_OR_GREATER

using System.Diagnostics;

Expand Down
12 changes: 6 additions & 6 deletions src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs
Expand Up @@ -94,12 +94,7 @@ public IDisposable ParseBeginScope<T>(T state)
}
}

#if !NET6_0
private static IReadOnlyList<KeyValuePair<string, object>> IncludeActivityIdsProperties(IReadOnlyList<KeyValuePair<string, object>> scopePropertyList)
{
return scopePropertyList; // Not supported
}
#else
#if NET5_0_OR_GREATER
private IReadOnlyList<KeyValuePair<string, object>> IncludeActivityIdsProperties(IReadOnlyList<KeyValuePair<string, object>> scopePropertyList)
{
if (_options.IncludeActivityIdsWithBeginScope && "RequestId".Equals(scopePropertyList[0].Key))
Expand Down Expand Up @@ -162,6 +157,11 @@ IEnumerator IEnumerable.GetEnumerator()
return ((IEnumerable)_originalPropertyList).GetEnumerator();
}
}
#else
private static IReadOnlyList<KeyValuePair<string, object>> IncludeActivityIdsProperties(IReadOnlyList<KeyValuePair<string, object>> scopePropertyList)
{
return scopePropertyList; // Not supported
}
#endif

public static IDisposable CaptureScopeProperties(IEnumerable scopePropertyCollection, ExtractorDictionary stateExtractor)
Expand Down
2 changes: 1 addition & 1 deletion src/NLog.Extensions.Logging/Logging/NLogProviderOptions.cs
Expand Up @@ -60,7 +60,7 @@ public class NLogProviderOptions
/// </summary>
public bool AutoShutdown { get; set; }

#if NET6_0
#if NET5_0_OR_GREATER
/// <summary>
/// Automatically include <see cref="System.Diagnostics.Activity.SpanId"/>, <see cref="System.Diagnostics.Activity.TraceId"/> and <see cref="System.Diagnostics.Activity.ParentId"/>
/// </summary>
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void AddNLog_LoggerFactory_LogInfoWithEventId_ShouldLogToNLogWithEventId(
AssertSingleMessage(memoryTarget, $"{expectedEventInLog} - test message with 1 arg");
}

#if NET6_0
#if NET6_0_OR_GREATER
[Fact]
public void AddNLog_LoggerFactory_IncludeActivityIdsWithBeginScope()
{
Expand Down

0 comments on commit 7caa533

Please sign in to comment.