Closed jchapmantcg closed 4 years ago
When #540 is merged and released, then things will get easier.
But while waiting for that, then I guess the following clumsy work-around can be used:
/* Register NLog.Web Extensions */
var dummy = LogginConfiguration();
NLogBuilder.ConfigureNLog(dummy);
/* Setup the actual confg, now has access to NLog.Web Extensions */
_logger = NLogBuilder.ConfigureNLog(config).GetCurrentClassLogger();
@snakefoot This produced the same results.
@jchapmantcg The ${aspnet-Request}
requires two things:
NLogBuilder.ConfigureNLog
until #540 is merged)You can setup the service-locator using AddNLog
or UseNLog
.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog(); // NLog: Setup NLog for Dependency injection (Make ${aspnet-Request} work)
See also: https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-3
This is what I was missing! Thanks @snakefoot
Type: Question/Bug
NLog version: 4.7.2
NLog.Web.AspNetCore version: 4.9.2
NLog.Extensions.Logging version: N/A
Platform: .NET Core 3.1
Current NLog config (xml or C#, if relevant)
In case of a BUG:
What is the current result? All ${aspnet-request-xxxx} vars are empty
What is the expected result? Values to be valid
Did you checked the Internal log? Yes. It did not show anything related.
Are there any workarounds? yes/no Not that I'm aware of.
Is there a version in which it did work? No.
Can you help us by writing an unit test? Yes.