Fix HTTP client logging config binding - #7691
Merged
Merged
Conversation
Fixes dotnet#7551 Use a static options configurator instead of generated configuration binding. The generated binder treats DataClassification values as complex objects because it does not honor their type converter. Preserve named options and configuration reload support. Add regression coverage for both registration paths, supported classification formats, invalid values, and reloads.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses dotnet/extensions #7551 by replacing generated configuration binding for HTTP client logging options with explicit, static binding logic so that DataClassification values bind correctly from configuration (including documented "None"/"Unknown" formats). It also preserves named-options behavior and configuration reload support, and adds regression coverage for both the IHttpClientBuilder and IServiceCollection registration paths.
Changes:
- Replaced
.Bind(section)usage with a customBindConfigurationSectionimplementation that correctly parsesDataClassification(scalar and object forms) and supports reload viaConfigurationChangeTokenSource. - Added explicit options configurators for both
LoggingOptions(Http Diagnostics) andLoggingRedactionOptions(ASP.NET Core middleware) to avoid the binder source generator’sDataClassificationhandling. - Added regression tests covering valid/invalid classifications, scalar parsing failures, missing sections, and reload behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Logging/HttpClientLoggingExtensionsTest.cs | Adds regression tests for config-based binding (including documented JSON), invalid values, and reloads for named and default options paths. |
| test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Logging/HttpLoggingServiceExtensionsTests.cs | Adds tests ensuring DataClassification binds correctly for HTTP logging redaction options and that invalid values throw with useful paths. |
| src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/LoggingOptionsConfigureOptions.cs | New explicit named-options binder for LoggingOptions, including DataClassification parsing and scalar/enum parsing with wrapped exceptions. |
| src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/LoggingOptionsBinder.cs | New internal OptionsBuilder<LoggingOptions> extension that wires the custom configurator plus reload token source. |
| src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/HttpClientLoggingServiceCollectionExtensions.cs | Switches config binding to the new BindConfigurationSection path. |
| src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/HttpClientLoggingHttpClientBuilderExtensions.cs | Switches config binding to the new BindConfigurationSection path for named clients (and wrapHandlersPipeline overload). |
| src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Logging/Internal/LoggingRedactionOptionsConfigureOptions.cs | New explicit binder for LoggingRedactionOptions to correctly parse DataClassification values from configuration. |
| src/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware/Logging/HttpLoggingServiceCollectionExtensions.cs | Replaces section.Bind(o) with the new explicit configurator registration for redaction options. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
evgenyfedorov2
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7551
Use a static options configurator instead of generated configuration
binding. The generated binder treats DataClassification values as complex
objects because it does not honor their type converter.
Preserve named options and configuration reload support. Add regression
coverage for both registration paths, supported classification formats,
invalid values, and reloads.
Microsoft Reviewers: Open in CodeFlow