HttpClient instances created by IHttpClientFactory will now log HTTP status codes as integers instead of with status code names #396
Labels
5.0.0
Announcements related to ASP.NET Core 5.0
Announcement
Breaking change
Documented
The breaking change has been published to the .NET Core docs
Milestone
HttpClient logging
HttpClient instances created by IHttpClientFactory will now log HTTP status codes as integers instead of with status code names.
Version introduced
5.0 preview 1
Old behavior
Logging would use the textual descriptions of HTTP status codes:
New behavior
Logging will use the integer values of HTTP status codes:
Reason for change
The original behavior of this logging is inconsistent with other parts of ASP.NET Core that have always used integer values. This inconsistency makes logs hard to query via structured logging systems such as ElasticSearch. See dotnet/extensions#1549
Using integer values is ultimately more flexible than text because it allows queries on ranges of values.
We considered adding an additional log value to capture the integer status code, but that would introduce another inconsistency with the rest of ASP.NET Core. HttpClient logging and HTTP server/hosting logging use the same key name (
StatusCode
) already.Recommended action
The best option is update logging queries to use the integer values of status codes. While this may cause some difficulty writing queries across multiple ASP.NET Core versions right now, we believe that using integers for this purpose is much more flexible for querying logs.
If for some reason you need to force compatibility with the old behavior, and use textual status codes, you can do this by replacing
IHttpClientFactory
's logging with your own.Copy the 3.1 versions of LoggingHttpMessageHandlerBuilderFilter LoggingHttpMessageHandler LoggingScopeHttpMessageHandler and HttpHeadersLogValue into your project.
Rename these types to avoid conflicts with public types in the
Microsoft.Extensions.Http
packageReplace the built-in implementation of
LoggingHttpMessageHandlerBuilderFilter
with your own insideStartup.Configure(IServiceProvider services)
Category
ASP.NET
Affected APIs
Not detectable via API analysis
Issue metadata
The text was updated successfully, but these errors were encountered: