Fix CA1848 documentation: Update link and add code examples #47579
+38
−1
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.
This PR improves the CA1848 rule documentation by updating an incorrect link and adding practical code examples to help developers understand how to fix violations.
Changes Made
Updated LoggerMessage Link
The rule description previously linked to the
LoggerMessage
API documentation, but now correctly points to the high-performance logging article that provides comprehensive guidance on implementing the pattern:Microsoft.Extensions.Logging.LoggerMessage
API docs/dotnet/core/extensions/high-performance-logging
articleAdded Code Examples
Added clear before/after examples in the "How to fix violations" section showing:
Code that violates CA1848:
Corrected code using LoggerMessage pattern:
These examples demonstrate the key differences:
partial class
declarationILogger
extension method calls with generated delegate methods[LoggerMessage]
attribute to define the log message templateThe documentation now provides developers with concrete examples they can reference when fixing CA1848 violations in their code.
Fixes #46239.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.