Configuration Value Source
You can track where a value came from with the LogConfigurationKeySource based methods. It will output the providers that have the given key, the last of which will be the provider that was used for the final value that is picked up by your application.
logger.LogConfigurationKeySource(LogLevel level, IConfigurationRoot configRoot, string key, bool compressed = false, ConfigurationDiagnosticsOptions options = null)
Where:
loggeris theILoggerwhere you want the information logged.configRootis theIConfigurationRootthat contains the provider information.levelis theLogLevelat which you wish the information to be logged.keyis the full key name of the configuration element you want to track.compressedindicates whether you want to skip providers that don’t provide a value for this item. The default isfalseso all providers are listed even if they do not provide a value for the givenkey. Whentrue, any providers that don’t provide a value for the givenkeywon’t be mentioned.optionsare the options to use for logging. If not supplied then theConfigurationDiagnosticsOptions.GlobalOptionsare used.
Example Output
info: Stravaig.Extensions.Configuration.Diagnostics.Tests.ConfigurationProviderTrackingExtensionsTests[0]
Provider sources for value of SomeSection:SomeKey
* MemoryConfigurationProvider ==> "SomeValue"
* MemoryConfigurationProvider ==> null
* JsonStreamConfigurationProvider ==> "SomeNewValue"
Alternative calls
There are a number of calls that imply the logging level in the method name instead of supplying it as a parameter. These are:
logger.LogConfigurationKeySourceAsInformation(IConfigurationRoot configRoot, string key, bool compressed = false, ConfigurationDiagnosticsOptions options = null)
logger.LogConfigurationKeySourceAsDebug(IConfigurationRoot configRoot, string key, bool compressed = false, ConfigurationDiagnosticsOptions options = null)
logger.LogConfigurationKeySourceAsTrace(IConfigurationRoot configRoot, string key, bool compressed = false, ConfigurationDiagnosticsOptions options = null)