How to set NLog's internal LogFile programmatically for dependency injection

356 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

Why not just remove internalLogFile="..." from NLog.{ASP_NET_CORE_ENVIRONMENT}.config ?

Or just re-assign InternalLogger.LogFile after having called LogManager.Setup().LoadConfigurationFromAppSettings() ?