From 3233de5f1855d58d21e3f959c9cbe2296496ec08 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Fri, 8 Dec 2023 18:48:47 +0100 Subject: [PATCH] UseNLog includes EnvironmentName when loading NLog config --- .../Extensions/ConfigureExtensions.cs | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs index 9aa83485..44e4a2b0 100644 --- a/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs +++ b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs @@ -72,13 +72,17 @@ private static void TryLoadConfigurationFromContentRootPath(LogFactory logFactor if (!string.IsNullOrEmpty(environmentName)) { - var nlogConfig = LoadXmlLoggingConfigurationFromPath(contentRootPath, $"NLog.{environmentName}.config", config.LogFactory) ?? LoadXmlLoggingConfigurationFromPath(contentRootPath, "NLog.config", config.LogFactory); + var nlogConfig = LoadXmlLoggingConfigurationFromPath(contentRootPath, $"NLog.{environmentName}.config", config.LogFactory) ?? + LoadXmlLoggingConfigurationFromPath(contentRootPath, $"nlog.{environmentName}.config", config.LogFactory) ?? + LoadXmlLoggingConfigurationFromPath(contentRootPath, "NLog.config", config.LogFactory) ?? + LoadXmlLoggingConfigurationFromPath(contentRootPath, "nlog.config", config.LogFactory); if (nlogConfig != null) config.Configuration = nlogConfig; } else { - var nlogConfig = LoadXmlLoggingConfigurationFromPath(contentRootPath, "NLog.config", config.LogFactory); + var nlogConfig = LoadXmlLoggingConfigurationFromPath(contentRootPath, "NLog.config", config.LogFactory) ?? + LoadXmlLoggingConfigurationFromPath(contentRootPath, "nlog.config", config.LogFactory); if (nlogConfig != null) config.Configuration = nlogConfig; } @@ -88,22 +92,8 @@ private static void TryLoadConfigurationFromContentRootPath(LogFactory logFactor private static LoggingConfiguration LoadXmlLoggingConfigurationFromPath(string contentRootPath, string nlogConfigFileName, LogFactory logFactory) { var standardPath = System.IO.Path.Combine(contentRootPath, nlogConfigFileName); - if (System.IO.File.Exists(standardPath)) - { - return new XmlLoggingConfiguration(standardPath, logFactory); - } - else - { - var lowercasePath = System.IO.Path.Combine(contentRootPath, nlogConfigFileName.ToLowerInvariant()); - if (System.IO.File.Exists(lowercasePath)) - { - return new XmlLoggingConfiguration(lowercasePath, logFactory); - } - else - { - return null; // Perform default loading - } - } + return System.IO.File.Exists(standardPath) ? + new XmlLoggingConfiguration(standardPath, logFactory) : null; } private static bool IsLoggingConfigurationLoaded(LoggingConfiguration cfg)