Class ConfigurationPrecedenceDiagnosticsExtensions
Minimal diagnostics for configuration provider order and key collisions.
Inherited Members
Namespace: Eigenverft.NetLib.Infrastructure.Hosting.Configuration.Diagnostics
Assembly: Eigenverft.NetLib.Infrastructure.dll
Syntax
public static class ConfigurationPrecedenceDiagnosticsExtensions
Methods
| Edit this page View SourceLogConfigurationResolution<TBuilder>(TBuilder, ILogger, LogLevel, LogLevel)
Logs configuration-provider precedence and reports keys shadowed by higher-precedence providers.
Call this as late as possible after the configuration-provider stack is complete and before Build().
Declaration
public static TBuilder LogConfigurationResolution<TBuilder>(this TBuilder builder, ILogger logger, LogLevel orderLogLevel = LogLevel.Information, LogLevel collisionLogLevel = LogLevel.Warning) where TBuilder : IHostApplicationBuilder
Parameters
| Type | Name | Description |
|---|---|---|
| TBuilder | builder | The host application builder whose current configuration-provider stack is inspected. |
| ILogger | logger | The logger receiving structured precedence and collision messages. Configuration values are never logged. |
| LogLevel | orderLogLevel | The level used for the provider-precedence message. The default is Information. |
| LogLevel | collisionLogLevel | The level used for collision and incomplete-scan messages. The default is Warning. |
Returns
| Type | Description |
|---|---|
| TBuilder | The same |
Type Parameters
| Name | Description |
|---|---|
| TBuilder |
Remarks
Add all declarative configuration providers before calling this method so the reported order represents the effective startup configuration. Prefer calling it before injecting runtime-only values that are not part of the intended provider-precedence model.
Example:
var builder = Host.CreateApplicationBuilder();
// Add/reset/load the complete configuration-provider stack first.
builder.Configuration.AddJsonFile("appsettings.json");
builder.Configuration.AddEnvironmentVariables();
var startupLogger = LoggerFactory.Create(logging => logging.AddConsole()).CreateLogger("Startup");
builder.LogConfigurationResolution(startupLogger);
using var host = builder.Build();
LogKeyCollisions(IConfiguration, ILogger, LogLevel)
Warns only for keys that exist in 2+ providers and shows the resolution chain (winner first).
Declaration
public static void LogKeyCollisions(IConfiguration configuration, ILogger logger, LogLevel level = LogLevel.Warning)
Parameters
| Type | Name | Description |
|---|---|---|
| IConfiguration | configuration | |
| ILogger | logger | |
| LogLevel | level |
Remarks
This emits a single summary line and then one warning per colliding key. The chain is printed in winner-first order (highest precedence to lowest precedence).
Example:
ConfigurationPrecedenceDiagnosticsExtensions.LogKeyCollisions(builder.Configuration, logger);
LogProviderOrder(IConfiguration, ILogger, LogLevel)
Logs the configuration provider order (precedence chain) once, as a single line with explicit direction.
Declaration
public static void LogProviderOrder(IConfiguration configuration, ILogger logger, LogLevel level = LogLevel.Information)
Parameters
| Type | Name | Description |
|---|---|---|
| IConfiguration | configuration | |
| ILogger | logger | |
| LogLevel | level |
Remarks
Prints provider origins in highest-to-lowest precedence order without exposing internal provider indices.
Example:
ConfigurationPrecedenceDiagnosticsExtensions.LogProviderOrder(builder.Configuration, logger);