Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseNLog includes EnvironmentName when loading NLog config #715

Merged
merged 1 commit into from Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs
Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down