Skip to content

Request to Add Logging for Configuration Events #110157

Open
@OlzhabaevSh

Description

@OlzhabaevSh

Issue

In many applications, it is crucial to have visibility into the configuration system, especially when debugging issues related to configuration loading and changes.
Currently, the .NET Configuration system does not provide built-in logging for when a new ConfigurationProvider is added or when a configuration provider reads configurations from.

Details

Not having this feature can mislead the debugging process because configurations often come from various sources such as environment variables, initialization files, multiple appsettings files, etc.
By default, there is no built-in mechanism to get a list of all configuration providers and the order in which they are registered in the Dependency Injection (DI) container during runtime.
This can be particularly tricky as different configuration values might override each other without clear visibility into the source and order of these configurations.

Additionally, most of the time, configuration setup can be obtained from a library, and you may not have direct access to the source code to see how the configurations are set up.
This lack of visibility can make it challenging to debug and understand the configuration hierarchy and precedence.

Feature description

Adding built-in logs for next events:

Event Fields
IConfigurationProvider added ConfigProviderName
A config item was read ConfigProviderName, KeyName, Value

Benifits

Adding these logs will help developers:

  • Debug configuration-related issues more effectively.
  • Gain insights into the configuration loading process.
  • Ensure that configuration changes are tracked and monitored.
  • Identify and resolve issues related to configuration value overrides.
  • Understand the configuration setup when using third-party libraries without direct access to their source code.

Risks

During the implementation of this feature, we should consider that some configuration keys may contain sensitive or restricted values.
These values could include passwords, connection strings, API keys, and other confidential information that should not be exposed in logs.
Logging such sensitive information could lead to security vulnerabilities and data breaches.

Mitigation Strategies

  1. Do Not Log Actual Values
  2. Sanitize Values

Do Not Log Actual Values

Avoid logging the actual values of configuration keys. Instead, log only the key names and the source of the configuration. This approach ensures that no sensitive information is exposed in the logs.

Sanitize Values

Implement logic to sanitize certain values before logging. For example, you can mask or redact values that contain sensitive information.
Specifically, you can:

  • Sanitize all values from keys that contain "connectionstring" or "secret" in their names.
  • Apply a general sanitization rule to mask any value that matches a pattern commonly used for sensitive data (e.g., passwords, API keys).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions