-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Seal NullLogger #117342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seal NullLogger #117342
Conversation
Sealing it makes type checks against it cheaper. Some libraries special-case ILogger instances that are NullLogger in order to avoid some logging-related overheads. While normally sealing a previously shipped public type would be a breaking change, NullLogger's only constructor is private, so types can't currently derive from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Seals the NullLogger
class to make type checks against it cheaper without breaking compatibility (its constructor is private).
- Changed
NullLogger
to a sealed class in the implementation assembly. - Updated the reference assembly to mark
NullLogger
as sealed.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/NullLogger.cs | Added sealed modifier to NullLogger |
src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs | Added sealed to the partial NullLogger |
Tagging subscribers to this area: @dotnet/area-extensions-logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just a one-off or did you write a script to look for such types?
One off being reminded of this by https://github.com/dotnet/runtime/pull/117334/files |
Sealing it makes type checks against it cheaper. Some libraries special-case ILogger instances that are NullLogger in order to avoid some logging-related overheads.
While normally sealing a previously shipped public type would be a breaking change, NullLogger's only constructor is private, so types can't currently derive from it.