Open kimsey0 opened 11 months ago
Tagging subscribers to this area: @dotnet/area-extensions-logging See info in area-owners.md if you want to be subscribed.
Author: | kimsey0 |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-Extensions-Logging` |
Milestone: | - |
@geeknoid and @maryamariyan, maybe you have some input on this based on your work on the current LoggingGenerator? Is this as straightforward as I see it?
Technically, this seems reasonable.
However, I thought that the logging scope thing was somewhat abandoned at this point. I think it was @davidfowl that mentioned this to me.
I didn't know scopes were being abandoned. There's nothing in the logging documentation nor the high-performance logging that indicates this. But if that's the case, this issue might not make sense. Perhaps instead the documentation should be updated to advice against using scopes.
This looks a duplicate of https://github.com/dotnet/runtime/issues/79028.
@tarekgh: Looking at #79028, this doesn't look to be a duplicate of it. #79028 proposes to add a scope parameter to generated [LoggerMessage]
methods. This asks to add separately generated methods for LoggerMessage.DefineScope
. Can we reopen it until we've determined if scopes are being deprecated altogether?
I am not aware the scope is abandoned. I see the scope is used heavily in all internal and external logger providers.
@kimsey0 do you think make sense merging the two proposals? I mean this one and https://github.com/dotnet/runtime/issues/79028? I am thinking of collecting all related scope scenarios together to support in the source gen. Ensure all of them work nicely together.
I'd love to hear what @davidfowl has to say on the general subject of logging scopes and their usefulness in general.
I've been personally attempting to abandoning scopes (https://github.com/dotnet/aspnetcore/pull/44873) in favor of activities and distributed tracing. I know it doesn't cover all scenarios but I think it works well for most cases. This just enrichment done with a more generic and less efficient api.
@tarekgh: I can't really see how the API proposed in #79028 would work. It suggests allowing a [LoggerScope] scope
parameter in [LoggerMessage]
methods, but doesn't address how to pass in arguments for the scope message format. I think it would be complicated and confusing to match parameters in the original declaration to placeholders in both the scope and log messages - what for example if both use the same placeholder with different casing? It seems limiting if it doesn't support arguments for the scope message at all. And in the first place, I don't understand the use case for a scope around just one message.
However, if you think both make sense to implement and to do together, I defer to your judgement.
if you think both make sense to implement and to do together, I defer to your judgement.
I am not pushing to have both at all. All I am trying to say is we need to ensure what makes sense to do with the scope in general and ensure we have a full story. We didn't have chance look deeply at https://github.com/dotnet/runtime/issues/79028. You may ignore it then for now.
Background and motivation
51064 introduced a new LoggingGenerator source generator which allows writing code like
and having an implementation using
LoggerMessage.Define
generated likeHowever, this doesn't support the other method for high-performance logging,
LoggerMessage.DefineScope
. This means that, if you use scopes, you will have manual calls toLoggerMessage.DefineScope
and the requisite delegate fields side-by-side with the new source generator approach:API Proposal
I suggest adding a new attribute side-by-side with the existing
LoggerMessageAttribute
and having LoggingGenerator generate calls to
LoggerMessage.DefineScope
, similar to the way it currently generates them forLoggerMessage.Define
.API Usage
This will allow defining logger messages and scopes in the same way:
Alternative Designs
No response
Risks
No response