Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit-test for NLogProviderOptions.IncludeActivtyIdsWithBeginScope #463

Merged
merged 1 commit into from
Dec 29, 2020
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