Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

petrroll
Copy link
Contributor

@petrroll petrroll commented Jul 8, 2025

Port of dotnet/runtime#117334

Microsoft Reviewers: Open in CodeFlow

@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 08:32
@petrroll petrroll requested a review from a team as a code owner July 8, 2025 08:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Instance providers in CreateLoggers
  • Add NullLoggerProvider to the provider list and verify it’s ignored
  • Import Microsoft.Extensions.Logging.Abstractions where 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>.Instance but the code only filters NullLogger.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-null Provider and not a NullLogger instance.
        var logger1 = (ExtendedLogger)factory.CreateLogger("C1");

src/Libraries/Microsoft.Extensions.Telemetry/Logging/ExtendedLoggerFactory.cs:234

  • Comparing only against NullLogger.Instance will not catch other possible null-logger types (e.g., NullLogger<T>). Consider using a type check like if (!(loggerInformation.Logger is NullLogger)) to filter all null loggers.
            if (loggerInformation.Logger != NullLogger.Instance)

@evgenyfedorov2
Copy link
Member

@geeknoid FYI

@evgenyfedorov2 evgenyfedorov2 merged commit 294a33d into dotnet:main Jul 8, 2025
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants