dotnet / dotnet/aspnetcore

[API Proposal]: HttpLogging improvements

Open
#56,126 0 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and motivation

Serilog enables this with [RequestLoggingOptions](https://github.com/serilog/serilog-aspnetcore/blob/70808dfda6e3618942041c9b578dce29d8033f83/src/Serilog.AspNetCore/AspNetCore/RequestLoggingOptions.cs#L25). Due to hard-coded log levels and formatting this is not possible with HttpLogging.

## Custom Message Format

The default format repeats every label which is hard to read, plus it is not structurally formatted ie. it uses a stringbuilder rather than assigning tag values.
```
Request and Response: server.address: example.com Path: /api/v1/path Protocol: HTTP/1.1 Method: GET Scheme: http QueryString: StatusCode: 200 Duration: 9.0314
```
If QueryString is included in the logs, I think it's preferable to print it as a single path in the logline, the QueryString tag is unaffected.

This could use some sensible default or enable a custom format to be provided by user.
```cs
namespace Microsoft.AspNetCore.HttpLogging;

public sealed class HttpLoggingOptions
{
+ public string MessageFormat { get; set; }
}
```
## Custom Log Level

Currently there's no way to override the log-level as it is always `info`. A different log level could be set in the interceptor context.
```cs
namespace Microsoft.AspNetCore.HttpLogging;

public sealed class HttpLoggingInterceptorContext
{
+ public LogLevel LogLevel { get; set; }
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.