Skip to content

Conversation

petrroll
Copy link
Contributor

@petrroll petrroll commented Jul 5, 2025

No description provided.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 5, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

@petrroll
Copy link
Contributor Author

petrroll commented Jul 6, 2025

I tried to think how to test this but other than adding InternalsVisibleTo (I assume no no) or reflection (eeh?) I don't see any way...

@KalleOlaviNiemitalo
Copy link

Could test the BeginScope optimization specifically.

  1. Set up a DI container with two logger providers:
    • The first ILoggerProvider returns NullLogger.Instance only.
    • The second ILoggerProvider creates loggers in which ILogger.BeginScope returns an instance of a custom type.
  2. Call ILoggerFactory.CreateLogger
  3. Call ILogger.BeginScope.
  4. Verify that the scope object is an instance of the custom type, i.e. it is not a wrapper created by Microsoft.Extensions.Logging.Logger.

@petrroll
Copy link
Contributor Author

petrroll commented Jul 6, 2025

Clever, good idea, added :)

@tarekgh
Copy link
Member

tarekgh commented Jul 7, 2025

@petrroll please try to not force-push again, this reset the review, and it is hard to tell what has changed since last review. Thanks!

@tarekgh tarekgh added this to the 10.0.0 milestone Jul 7, 2025
@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jul 7, 2025

Are there benchmark numbers? For initialisation of logging, and for ILogger.Log in steady state after the ILogger has been created by LoggerFactory.

@petrroll
Copy link
Contributor Author

petrroll commented Jul 7, 2025

@KalleOlaviNiemitalo do we need that? Creating logger will be marginally worse with especially worse allocations, logging will be faster - but depending on the Perf of any used logger might or might not be dwarfed.

It doesn't seem particularly useful. This is clean, relatively simple solution. What would we achieve with it?

@KalleOlaviNiemitalo
Copy link

I don't insist on benchmarking this, but if you have done the benchmark, then I am curious to see the numbers.

@petrroll
Copy link
Contributor Author

petrroll commented Jul 7, 2025

I haven't so regrettably I can't share. It was motivated by being annoyed that one of may changes at work could to 20+ loggers that are reach only for one category and noticing other libraries doing similar things. Purely that :)

@tarekgh
Copy link
Member

tarekgh commented Jul 7, 2025

/ba-g there is one failure which is looks outage or infra unrelated issue.

@tarekgh tarekgh merged commit cbb1610 into dotnet:main Jul 8, 2025
77 of 87 checks passed
@tarekgh
Copy link
Member

tarekgh commented Jul 8, 2025

Thanks @petrroll for providing the change.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Logging community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants