Skip to content

Commit

Permalink
UseNLog should fallback after checking ContentRoot for NLog.config (t…
Browse files Browse the repository at this point in the history
…est) (#1061)
  • Loading branch information
snakefoot authored Sep 25, 2024
1 parent bb70f16 commit a6f8cb2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/NLog.Web.AspNetCore.Tests/AspNetCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,19 @@ public void UseNLogContentRootTest()
System.IO.Directory.CreateDirectory(tempPath);
System.IO.Directory.SetCurrentDirectory(tempPath);

var configChanged = false;

LogManager.ConfigurationChanged += (args, sender) => configChanged = true;

using var webhost = CreateWebHost();

var hostEnvironment = webhost.Services.GetRequiredService<Microsoft.Extensions.Hosting.IHostEnvironment>();
Assert.NotNull(hostEnvironment.ContentRootPath);
Assert.False(configChanged); // Scanned ContentRoot without assigning any default config

var loggerFact = GetLoggerFactory(webhost.Services);

Assert.NotNull(loggerFact);

Assert.Null(LogManager.Configuration); // Scanned ContentRoot without assigning any default config

var configuration = CreateConfigWithMemoryTarget(out var target, "${logger}|${message}|${callsite}");

LogManager.Setup().RegisterNLogWeb(serviceProvider: webhost.Services).LoadConfiguration(configuration);
Expand Down

0 comments on commit a6f8cb2

Please sign in to comment.