Skip to content

Commit 1a17362

Browse files
authored
NLogProviderOptions - Use LogFactory from provider when using LoggingConfigurationSectionName (#508)
1 parent 1993d5c commit 1a17362

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ public static ISetupBuilder LoadConfigurationFromSection(this ISetupBuilder setu
1717
if (!string.IsNullOrEmpty(configSection))
1818
{
1919
var nlogConfig = configuration.GetSection(configSection);
20-
if (nlogConfig?.GetChildren().Any() == true)
20+
if (nlogConfig?.GetChildren()?.Any() == true)
2121
{
2222
setupBuilder.LogFactory.Configuration = new NLogLoggingConfiguration(nlogConfig, setupBuilder.LogFactory);
2323
}
24+
else
25+
{
26+
Common.InternalLogger.Debug("Skip loading NLogLoggingConfiguration from empty config section: {0}", configSection);
27+
}
2428
}
2529
return setupBuilder;
2630
}

src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ internal static void TryLoadConfigurationFromSection(this NLogLoggerProvider log
4747
{
4848
if (configBuilder.Configuration.LoggingRules.Count == 0 && configBuilder.Configuration.AllTargets.Count == 0)
4949
{
50-
configBuilder.Configuration = new NLogLoggingConfiguration(nlogConfig);
50+
configBuilder.Configuration = new NLogLoggingConfiguration(nlogConfig, loggerProvider.LogFactory);
5151
}
5252
});
5353
}
54+
else
55+
{
56+
Common.InternalLogger.Debug("Skip loading NLogLoggingConfiguration from empty config section: {0}", loggerProvider.Options.LoggingConfigurationSectionName);
57+
}
5458
}
5559
}
5660
}

0 commit comments

Comments
 (0)