[Hosting] Add {OriginalFormat} to start & stop log state objects#45253
Conversation
|
Thanks for your PR, @CodeBlanch. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
If we're going to do this, we should do it for all our custom logging: |
|
@BrennanConroy Thanks for the link! I don't think |
|
cc @samsp-msft |
halter73
left a comment
There was a problem hiding this comment.
Agreed about the scopes. Even for the HttpLogging middleware, I don't think there's a great {OriginalFormat} since it's so dynamic. I think we should just take this as a starting point. If someone else has a good idea for the other logs, we can merge that separately.
Description
The
ILoggerextensions and source generator return the original template logged as the {OriginalFormat} key on the IReadOnlyList<KeyValuePair<string, object>> state representing the log being written.AspNetCore has a couple custom log states which do not mirror the
{OriginalFormat}behavior. By default OpenTelemetry only captures message templates but for these logs it must either have empty template/body (confusing for users) or invokeToString(and incur allocations) to generate a formatted string because no template is available.In order to make these high value logs play nicely with structured logging and to enable high performance capture I'm proposing we should mirror the
{OriginalFormat}behavior.Changes
{OrignalFormat}as the last key onHostingRequestStartingLog&HostingRequestFinishedLogstate objectsFinal templates look like this:
Start:
Request starting {Protocol} {Method} {Scheme}://{Host}{PathBase}{Path}{QueryString} - {ContentType} {ContentLength}Stop:
Request finished {Protocol} {Method} {Scheme}://{Host}{PathBase}{Path}{QueryString} - {StatusCode} {ContentLength} {ContentType} {ElapsedMilliseconds}ms/cc @davidfowl @tarekgh @noahfalk @cijothomas @utpilla @reyang