0

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?

Progman
  • 16,827
  • 6
  • 33
  • 48
Eternal21
  • 4,190
  • 2
  • 48
  • 63
  • How exactly is setting `NLog.Common.InternalLogger.LogFile` in your case not working? Please [edit] your question to include a [mcve], which show the problem you have with `NLog.Common.InternalLogger.LogFile`. And how is the internal logger relevant for you when using an injectect `NLog` instance? – Progman Apr 23 '22 at 10:31
  • 1. It's not working, because it gets overriden by the "NLog.{ASP_NET_CORE_ENVIRONMENT}.config that I'm guessing is wired up by .UseNLog() extension function. 2. Internal log is relevant, because I want to be able to be able to output NLog internal errors to the file I specify. – Eternal21 Apr 23 '22 at 16:12
  • @Eternal21 Why not just remove `internalLogFile="..."` from `NLog.{ASP_NET_CORE_ENVIRONMENT}.config` ? Or just re-assign `InternalLogger.LogFile` after having called `LogManager.Setup().LoadConfigurationFromAppSettings()` ? – Rolf Kristensen Apr 24 '22 at 17:23
  • @RolfKristensen Your first suggestion worked. If you post it as an answer, I'll accept it. – Eternal21 Apr 26 '22 at 00:44

1 Answers1

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() ?

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70