-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve nullable annotations for ILogger.BeginScope
#66960
Improve nullable annotations for ILogger.BeginScope
#66960
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-extensions-logging Issue DetailsBased on this discussion: #66892 (comment)
|
cc @davidfowl @lodejard @rynowak @BrennanConroy @halter73 - FYI, in case you have any feedback on this annotation. Specifically, the runtime/src/libraries/Microsoft.Extensions.Logging.EventLog/src/EventLogLogger.cs Lines 51 to 54 in eb51b02
|
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.
LGTM - assuming no one else has any feedback.
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.
Scopes aren't supported by all loggers so the IDisposable?
makes sense to me.
@@ -20,7 +20,7 @@ private NullLogger() | |||
} | |||
|
|||
/// <inheritdoc /> | |||
public IDisposable BeginScope<TState>(TState state) | |||
public IDisposable BeginScope<TState>(TState state) where TState : notnull |
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.
Just curious, how does this not complain about hiding the nullable annotation on ILogger.BeginScope?
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.
Your interface implementation can be more specific than the interface. Here the interface says "You can return an IDisposable, or null". And this implementation says "I only ever return an IDisposable", which is allowed.
The inverse isn't allowed though.
I'm going to merge this. If anyone else has feedback, we can open a new PR to address it. |
* BeginScope can return a null IDisposable. And TState is not nullable.
Based on this discussion: #66892 (comment)