Open paulomorgado opened 9 months ago
Tagging subscribers to this area: @dotnet/area-extensions-logging See info in area-owners.md if you want to be subscribed.
Author: | paulomorgado |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-Extensions-Logging` |
Milestone: | - |
I don't understand why this would be necessary. If used in a using
the compiler already inserts a null
check on the disposable before calling Dispose
. SharpLab
Some info there: https://github.com/dotnet/runtime/issues/63867
Not all loggers do support scopes. This might give the false impression there is a scope so now we have to check if the returned object is a nullscope v.s. checking for null?
Background and motivation
Even though the contract for
ILogger.BeginScope<TState>(TState)
states the the return value can benull
(IDisposable?
), actually returningnull
should be avoided.The correct usage of the API should be something like:
API Proposal
API Usage
Alternative Designs
Provide an empty
IDisposable
implementation in the BCL to avoid reimplementation and external dependencies.Risks
No response