public void Configure(EgressOptions options) { IConfigurationSection egressSection = _configuration.GetEgressSection(); IConfigurationSection propertiesSection = egressSection.GetSection(nameof(EgressOptions.Properties)); propertiesSection.Bind(options.Properties); _logger.LogDebug("Start loading egress providers."); IConfigurationSection providersSection = egressSection.GetSection(nameof(EgressOptions.Providers)); foreach (var providerSection in providersSection.GetChildren()) { string providerName = providerSection.Key; using var providerNameScope = _logger.BeginScope(new Dictionary <string, string>() { { "ProviderName", providerName } }); CommonEgressProviderOptions commonOptions = new CommonEgressProviderOptions(); providerSection.Bind(commonOptions); EgressProviderValidation validation = new EgressProviderValidation(providerName, _logger); if (!validation.TryValidate(commonOptions)) { _logger.LogWarning("Provider '{0}': Skipped: Invalid options.", providerName); } string providerType = commonOptions.Type; using var providerTypeScope = _logger.BeginScope(new Dictionary <string, string>() { { "ProviderType", providerType } }); if (!_factories.TryGetValue(providerType, out EgressFactory factory)) { _logger.LogWarning("Provider '{0}': Skipped: Type '{1}' is not supported.", providerName, providerType); continue; } if (!factory.TryCreate(providerName, providerSection, options.Properties, out ConfiguredEgressProvider provider)) { _logger.LogWarning("Provider '{0}': Skipped: Invalid options.", providerName); continue; } options.Providers.Add(providerName, provider); _logger.LogInformation("Added egress provider '{0}'.", providerName); } _logger.LogDebug("End loading egress providers."); }
public void Configure(EgressOptions options) { IConfigurationSection egressSection = _configuration.GetEgressSection(); IConfigurationSection propertiesSection = egressSection.GetSection(nameof(EgressOptions.Properties)); propertiesSection.Bind(options.Properties); IConfigurationSection providersSection = egressSection.GetSection(nameof(EgressOptions.Providers)); foreach (var providerSection in providersSection.GetChildren()) { string providerName = providerSection.Key; KeyValueLogScope providerNameScope = new KeyValueLogScope(); providerNameScope.Values.Add("EgressProviderName", providerName); using var providerNameRegistration = _logger.BeginScope(providerNameScope); CommonEgressProviderOptions commonOptions = new CommonEgressProviderOptions(); providerSection.Bind(commonOptions); EgressProviderValidation validation = new EgressProviderValidation(providerName, _logger); if (!validation.TryValidate(commonOptions)) { _logger.EgressProviderInvalidOptions(providerName); } string providerType = commonOptions.Type; KeyValueLogScope providerTypeScope = new KeyValueLogScope(); providerTypeScope.Values.Add("EgressProviderType", providerType); using var providerTypeRegistration = _logger.BeginScope(providerTypeScope); if (!_factories.TryGetValue(providerType, out EgressFactory factory)) { _logger.EgressProviderInvalidType(providerName, providerType); continue; } if (!factory.TryCreate(providerName, providerSection, options.Properties, out ConfiguredEgressProvider provider)) { _logger.EgressProviderInvalidOptions(providerName); continue; } options.Providers.Add(providerName, provider); _logger.EgressProviderAdded(providerName); } }