Skip to content

Commit

Permalink
LoadConfigurationFromSection should RegisterConfigSettings without co…
Browse files Browse the repository at this point in the history
…nfiguration assign (#632)
  • Loading branch information
snakefoot authored Oct 27, 2022
1 parent e836eac commit c69d069
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class SetupBuilderExtensions
/// </summary>
public static ISetupBuilder LoadConfigurationFromSection(this ISetupBuilder setupBuilder, Microsoft.Extensions.Configuration.IConfiguration configuration, string configSection = "NLog")
{
setupBuilder.SetupExtensions(ext => ext.RegisterExtensionsLogging(configuration));
setupBuilder.SetupExtensions(ext => ext.RegisterConfigSettings(ConfigSettingLayoutRenderer.DefaultConfiguration ?? configuration));
if (!string.IsNullOrEmpty(configSection))
{
var nlogConfig = configuration.GetSection(configSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ public static class SetupExtensionsBuilderExtensions
/// </summary>
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<ConfigSettingLayoutRenderer>("configsetting").RegisterLayoutRenderer<MicrosoftConsoleLayoutRenderer>("MicrosoftConsoleLayout").RegisterLayout<MicrosoftConsoleJsonLayout>("MicrosoftConsoleJsonLayout");
ConfigSettingLayoutRenderer.DefaultConfiguration = configuration ?? ConfigSettingLayoutRenderer.DefaultConfiguration;
return setupBuilder.RegisterLayoutRenderer<ConfigSettingLayoutRenderer>("configsetting")
.RegisterLayoutRenderer<MicrosoftConsoleLayoutRenderer>("MicrosoftConsoleLayout")
.RegisterLayout<MicrosoftConsoleJsonLayout>("MicrosoftConsoleJsonLayout");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static NLogLoggerProvider CreateNLogLoggerProvider(this IServiceProvide

internal static IConfiguration SetupNLogConfigSettings(this IServiceProvider serviceProvider, IConfiguration configuration, LogFactory logFactory)
{
configuration = configuration ?? (serviceProvider?.GetService(typeof(IConfiguration)) as IConfiguration) ?? ConfigSettingLayoutRenderer.DefaultConfiguration;
configuration = configuration ?? (serviceProvider?.GetService(typeof(IConfiguration)) as IConfiguration);
logFactory.Setup().SetupExtensions(ext => ext.RegisterConfigSettings(configuration));
return configuration;
}
Expand Down

0 comments on commit c69d069

Please sign in to comment.