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

LoadConfigurationFromSection should RegisterConfigSettings without configuration assign #632

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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