Ingore null loggers returned by LogProviders in ELoggerFactory#6585
Merged
evgenyfedorov2 merged 1 commit intodotnet:mainfrom Jul 8, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ports logic to ignore null loggers from LogProviders in ExtendedLoggerFactory and adds a corresponding test to verify the behavior.
- Filter out
NullLogger.Instanceproviders inCreateLoggers - Add
NullLoggerProviderto the provider list and verify it’s ignored - Import
Microsoft.Extensions.Logging.Abstractionswhere needed
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.Telemetry/Logging/ExtendedLoggerFactory.cs | Change CreateLoggers to use a list, skip NullLogger.Instance, and return an array |
| test/Libraries/Microsoft.Extensions.Telemetry.Tests/Logging/ExtendedLoggerFactoryTests.cs | Add a test (NullLoggerByProviderIsIgnored) to ensure null loggers are not included |
Comments suppressed due to low confidence (3)
src/Libraries/Microsoft.Extensions.Telemetry/Logging/ExtendedLoggerFactory.cs:232
- The comment mentions
NullLogger<T>.Instancebut the code only filtersNullLogger.Instance. Update the comment to accurately reflect what the code is checking or adjust the code to match the comment.
// We do not need to check for NullLogger<T>.Instance as no provider would reasonably return it (the <T> handling is at
test/Libraries/Microsoft.Extensions.Telemetry.Tests/Logging/ExtendedLoggerFactoryTests.cs:548
- [nitpick] The test checks only the count of
MessageLoggers. To make it more robust, assert that the remaining logger is indeed from the non-nullProviderand not aNullLoggerinstance.
var logger1 = (ExtendedLogger)factory.CreateLogger("C1");
src/Libraries/Microsoft.Extensions.Telemetry/Logging/ExtendedLoggerFactory.cs:234
- Comparing only against
NullLogger.Instancewill not catch other possible null-logger types (e.g.,NullLogger<T>). Consider using a type check likeif (!(loggerInformation.Logger is NullLogger))to filter all null loggers.
if (loggerInformation.Logger != NullLogger.Instance)
Member
|
@geeknoid FYI |
evgenyfedorov2
approved these changes
Jul 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of dotnet/runtime#117334
Microsoft Reviewers: Open in CodeFlow