'How to set NLog's internal LogFile programmatically for dependency injection
I know you can set NLog's internal log file programmatically like this:
NLog.Common.InternalLogger.LogFile = @"C:\Logs\nlog.log";
The above trick does not work for the following scenario, where I need to be able to set internal log file that's used by injected NLog. The one that gets created inside ASP.NET Core WebApi, using the following
.ConfigureLogging(logging =>
{
logging.SetMinimumLevel(LogLevel.Trace);
})
.UseNLog();
Are there any workarounds for me to programmatically configure LogFile and LogLeve of the NLog object that gets dependency injected?
Solution 1:[1]
Why not just remove internalLogFile="..." from NLog.{ASP_NET_CORE_ENVIRONMENT}.config ?
Or just re-assign InternalLogger.LogFile after having called LogManager.Setup().LoadConfigurationFromAppSettings() ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rolf Kristensen |
