diff --git a/src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs b/src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs index 1db4320b..c327c056 100644 --- a/src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs +++ b/src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs @@ -13,6 +13,7 @@ public static class SetupBuilderExtensions /// public static ISetupBuilder LoadConfigurationFromSection(this ISetupBuilder setupBuilder, Microsoft.Extensions.Configuration.IConfiguration configuration, string configSection = "NLog") { + setupBuilder.SetupExtensions(ext => ext.RegisterExtensionsLogging(configuration)); if (!string.IsNullOrEmpty(configSection)) { var nlogConfig = configuration.GetSection(configSection); diff --git a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs index 91476728..63a77550 100644 --- a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs +++ b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs @@ -14,6 +14,15 @@ public static class SetupExtensionsBuilderExtensions public static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration) { ConfigSettingLayoutRenderer.DefaultConfiguration = configuration; + return setupBuilder.RegisterExtensionsLogging(configuration); + } + + internal static ISetupExtensionsBuilder RegisterExtensionsLogging(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration) + { + if (ConfigSettingLayoutRenderer.DefaultConfiguration is null) + { + ConfigSettingLayoutRenderer.DefaultConfiguration = configuration; + } return setupBuilder.RegisterLayoutRenderer("configsetting").RegisterLayoutRenderer("MicrosoftConsoleLayout"); } }