Skip to content

Fix up code snippets and descriptions#51524

Open
gewarren wants to merge 5 commits intodotnet:mainfrom
gewarren:logging-provider
Open

Fix up code snippets and descriptions#51524
gewarren wants to merge 5 commits intodotnet:mainfrom
gewarren:logging-provider

Conversation

@gewarren
Copy link
Contributor

@gewarren gewarren commented Feb 5, 2026

Contributes to #41327 (fragments left in document).


Internal previews

📄 File 🔗 Preview link
docs/core/extensions/logging/custom-provider.md Implement a custom logging provider in .NET

@gewarren gewarren requested a review from a team as a code owner February 5, 2026 02:29
Copilot AI review requested due to automatic review settings February 5, 2026 02:29
@dotnetrepoman dotnetrepoman bot added this to the February 2026 milestone Feb 5, 2026
Copy link
Contributor

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 addresses Issue #41327 by fixing code snippets and improving descriptions in the custom logging provider documentation. The main issue was that the documentation contained unexplained code fragments (specifically parameter lines from a method signature) that confused readers.

Changes:

  • Replaced the meaningless code snippet showing parameter fragments with a proper snippet reference that demonstrates the IsEnabled check pattern
  • Improved heading hierarchy by promoting subsections from H3 to H2 for better document structure
  • Enhanced clarity in various descriptions and converted text to be more conversational and aligned with Microsoft's documentation style guidelines

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
docs/core/extensions/snippets/configuration/console-custom-logging/ColorConsoleLogger.cs Added snippet markers around the IsEnabled check for better code reuse in documentation
docs/core/extensions/logging/custom-provider.md Fixed code snippet references, improved heading structure, enhanced descriptive text, added tables for better visual clarity, and updated metadata date
Comments suppressed due to low confidence (1)

docs/core/extensions/logging/custom-provider.md:58

  • The highlight now only emphasizes line 7 (ProviderAlias attribute), but the explanatory text on lines 57-58 describes both the UnsupportedOSPlatform attribute (line 6) and the ProviderAlias attribute (line 7). Consider highlighting both lines 6-7 to match the text, or adjust the text to focus primarily on the ProviderAlias attribute.
:::code language="csharp" source="../snippets/configuration/console-custom-logging/ColorConsoleLoggerProvider.cs" range="6-8" highlight="7":::

The `ColorConsoleLoggerProvider` class defines two class-scoped attributes:

- <xref:System.Runtime.Versioning.UnsupportedOSPlatformAttribute>: The `ColorConsoleLogger` type is _not supported_ in the `"browser"`.
- <xref:Microsoft.Extensions.Logging.ProviderAliasAttribute>: Configuration sections can define options using the `"ColorConsole"` key.

Copy link
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

docs/core/extensions/logging/custom-provider.md:85

  • According to markdown style guidelines, the title should be in sentence case. "app" should be lowercase rather than uppercase "App" to follow the guideline of capitalizing only the first word and proper nouns in headings and text.
- [Dependency injection in .NET](../dependency-injection/overview.md)

Running this simple application will render color output to the console window similar to the following image:
The `ILoggingBuilder` creates one or more `ILogger` instances. The `ILogger` instances are used by the framework to log the information.

The instantiation code overrides the color values from the _appsettings.json_ file for <xref:Microsoft.Extensions.Logging.LogLevel.Warning?displayProperty=nameWithType> and <xref:Microsoft.Extensions.Logging.LogLevel.Error?displayProperty=nameWithType>.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The highlight range "8-14" appears to be incorrect. Looking at the Program.cs file, line 8 is the call to AddColorConsoleLogger, which starts the configuration block, but the closing bracket is on line 16, not line 14. The highlight should be "8-16" to include the complete AddColorConsoleLogger call.

Copilot uses AI. Check for mistakes.
It's a good practice to call <xref:Microsoft.Extensions.Logging.ILogger.IsEnabled*?displayProperty=nameWithType> within <xref:Microsoft.Extensions.Logging.ILogger.Log*?displayProperty=nameWithType> implementations since `Log` can be called by any consumer, and there are no guarantees that it was previously checked. The `IsEnabled` method should be very fast in most implementations.

It's a good practice to call <xref:Microsoft.Extensions.Logging.ILogger.IsEnabled%2A?displayProperty=nameWithType> within <xref:Microsoft.Extensions.Logging.ILogger.Log%2A?displayProperty=nameWithType> implementations since `Log` can be called by any consumer, and there are no guarantees that it was previously checked. The `IsEnabled` method should be very fast in most implementations.
:::code language="csharp" source="../snippets/configuration/console-custom-logging/ColorConsoleLogger.cs" range="20-23":::
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The code range "19-22" only shows the opening brace of the Log method and the early return check. Based on the context in line 31, which explains that "It's a good practice to call IsEnabled within Log implementations," the range should likely be "20-23" to show the complete IsEnabled check including the closing brace, or the range should be adjusted to show the meaningful part of the implementation.

Suggested change
:::code language="csharp" source="../snippets/configuration/console-custom-logging/ColorConsoleLogger.cs" range="20-23":::
:::code language="csharp" source="../snippets/configuration/console-custom-logging/ColorConsoleLogger.cs":::

Copilot uses AI. Check for mistakes.
Comment on lines 1 to 6
---
title: Implement a custom logging provider
description: Discover how to implement a custom logging provider with colorized logs, writing custom C# ILogger and ILoggerProvider implementations.
ms.date: 10/20/2025
ms.date: 02/04/2026
ms.topic: how-to
---
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

According to the .NET Documentation Guidelines (CodingGuidelineID: 1000000), Markdown files that have been generated or significantly modified with AI assistance should include an ai-usage frontmatter key. Since this PR involves substantial edits and improvements, consider adding ai-usage: ai-assisted to the frontmatter if AI was used to assist with these changes.

Copilot generated this review using guidance from repository custom instructions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant