Eternal21
Eternal21

Reputation: 4684

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?

Upvotes: 0

Views: 504

Answers (1)

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

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

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

Upvotes: 1

Related Questions