Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NLog.Targets;
using Xunit;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;

namespace NLog.Extensions.Logging.Tests.Extensions
{
Expand Down Expand Up @@ -50,6 +51,30 @@ public void AddNLog_LoggerFactory_LogInfoWithEventId_ShouldLogToNLogWithEventId(
AssertSingleMessage(memoryTarget, $"{expectedEventInLog} - test message with 1 arg");
}

#if NET5_0
[Fact]
public void AddNLog_LoggerFactory_IncludeActivtyIdsWithBeginScope()
{
// Arrange
var loggerFactory = new LoggerFactory();
var config = CreateConfigWithMemoryTarget(out var memoryTarget, $"${{mdlc:ParentId}} - ${{message}}");

// Act
loggerFactory.AddNLog(new NLogProviderOptions { IncludeActivtyIdsWithBeginScope = true });
LogManager.Configuration = config;
var logger = loggerFactory.CreateLogger(nameof(AddNLog_LoggerFactory_IncludeActivtyIdsWithBeginScope));
var activity = new System.Diagnostics.Activity("TestActivity").SetParentId("42").Start();
var scopeProperties = new Dictionary<string, object> { { "RequestId", "123" }, { "RequestPath", "Unknown" } };
using (logger.BeginScope(scopeProperties.ToList()))
{
logger.LogInformation(default(EventId), "test message with {0} arg", 1);
}

// Assert
AssertSingleMessage(memoryTarget, "42 - test message with 1 arg");
}
#endif

#if !NETCOREAPP1_1 && !NET452
[Fact]
public void AddNLog_LoggingBuilder_LogInfo_ShouldLogToNLog()
Expand Down