You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Behavior changes between .NET logging generator and .NET extensions #5332
I inherited from that class as intended by the Azure Mobile Apps SDK and in my class have a more specific ILogger<T> property as follows:
publicpartialclassInspectionSyncController:TableController<FarmInspectionSyncModel>{privatereadonlyILogger<InspectionSyncController>logger;publicInspectionSyncController(...ILogger<InspectionSyncController>logger):base(...){...this.logger=logger;}...[LoggerMessage(EventId=0,Level=LogLevel.Warning,Message="Not authorized to perform operation `{Operation}` on entity `{EntityId}`")]privatepartialvoidLogNotAuthorizedToPerformOperationOnEntity(TableOperationoperation,string?entityId);...}
This works without Microsoft.Extensions.Http.Resilience.
Actual behavior
After adding Microsoft.Extensions.Http.Resilience, I get this warning:
@hansmbakker your case is a little different than the one in the original post. When including the Microsoft.Extensions.Http.Resilience package, it replaces the .NET logging generator with the .NET extensions logging generator. This has slightly different behavior as seen with diagnostic warning. You can get around this by providing an ILogger parameter to the method and making it static:
publicpartialclassInspectionSyncController:TableController<FarmInspectionSyncModel>{privatereadonlyILogger<InspectionSyncController>logger;publicInspectionSyncController(...ILogger<InspectionSyncController>logger):base(...){...this.logger=logger;}...[LoggerMessage(EventId=0,Level=LogLevel.Warning,Message="Not authorized to perform operation `{Operation}` on entity `{EntityId}`")]privatestaticpartialvoidLogNotAuthorizedToPerformOperationOnEntity(ILoggerlogger,TableOperationoperation,string?entityId);...}
@geeknoid should we consider this a bug and bring parity to the way the .NET generator works? To only use the most derived logger member?
Ideally we'd want the dotnet/extensions logger be a superset of features on top of the inbox one, to facilitate onboarding and upgrade scenarios, so whenever possible, we should really try to have parity. Is there a scenario in the extensions logger space that would break if we change this particular behavior to match the inbox logger?
it replaces the .NET logging generator with the .NET extensions logging generator
Question without knowing the context - what causes the need for a replacement of the default .NET logger source generator? Could the extensions packages not simply take a dependency on that default .NET logger source generator?
The logger in this repository has some additional features on top of the built-in one (like for example it allows you do to redaction or enrichment on your log messages and it also allows logging full object's state) but the way source generator works, doesn't really allow for them to compose very well. For logging, the generator typically fills in the implementation of a logging method, but doesn't really have extensibility points for an additional generator to enhance it, so for now we instead replace the generator so that we can fill in the implementation of the logger method.
@dariusclay Yeah, it's probably reasonable to follow the behavior from the original logger. I suspect this behavior was added to dotnet/runtime at some point and I missed replicating that into the dotnet/extensions code generator.
Reacted by Jose Perez Rodriguez and Darius Letterman
Activity
dariusclay commentedon Aug 2, 2024
@hansmbakker I've moved the thread here
dariusclay commentedon Aug 2, 2024
@geeknoid should we consider this a bug and bring parity to the way the .NET generator works? To only use the most derived logger member?
dariusclay commentedon Aug 5, 2024
@joperezr do you have any opinions on this?
dariusclay commentedon Aug 5, 2024
Related to #5336
joperezr commentedon Aug 5, 2024
Ideally we'd want the dotnet/extensions logger be a superset of features on top of the inbox one, to facilitate onboarding and upgrade scenarios, so whenever possible, we should really try to have parity. Is there a scenario in the extensions logger space that would break if we change this particular behavior to match the inbox logger?
hansmbakker commentedon Aug 5, 2024
Question without knowing the context - what causes the need for a replacement of the default .NET logger source generator? Could the extensions packages not simply take a dependency on that default .NET logger source generator?
joperezr commentedon Aug 5, 2024
The logger in this repository has some additional features on top of the built-in one (like for example it allows you do to redaction or enrichment on your log messages and it also allows logging full object's state) but the way source generator works, doesn't really allow for them to compose very well. For logging, the generator typically fills in the implementation of a logging method, but doesn't really have extensibility points for an additional generator to enhance it, so for now we instead replace the generator so that we can fill in the implementation of the logger method.
dariusclay commentedon Aug 6, 2024
@joperezr I don't think that there would be anything necessarily breaking if we align behavior, but will deep-dive to see.
geeknoid commentedon Aug 13, 2024
@dariusclay Yeah, it's probably reasonable to follow the behavior from the original logger. I suspect this behavior was added to dotnet/runtime at some point and I missed replicating that into the dotnet/extensions code generator.
dariusclay commentedon Aug 15, 2024
Thanks @geeknoid! I'm working on tacking this one piece at a time