Fix redacting log article: pushed code out to snippets and added missing classes#55006
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the compile-time logging source-generation article to use external snippet files (instead of inline code blocks) and fixes the “Redacting sensitive information in logs” example by including the previously missing supporting types in the snippet source.
Changes:
- Replaced multiple inline C# examples in
source-generation.mdwith:::codesnippet references. - Added a new C# snippets project and extracted example code into dedicated snippet files.
- Added supporting redaction and data-classification types to make the redaction example self-contained.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/core/extensions/logging/source-generation.md | Replaces inline examples with snippet references, including the redaction section. |
| docs/core/extensions/logging/snippets/source-generation/csharp/csharp.csproj | Adds a snippet project to compile the extracted examples. |
| docs/core/extensions/logging/snippets/source-generation/csharp/Program.cs | Adds a minimal entry point for the snippets project. |
| docs/core/extensions/logging/snippets/source-generation/csharp/BasicUsage/StaticLog.cs | Adds snippet source for basic static LoggerMessage usage. |
| docs/core/extensions/logging/snippets/source-generation/csharp/BasicUsage/ExtensionLog.cs | Adds snippet source for extension-method LoggerMessage usage. |
| docs/core/extensions/logging/snippets/source-generation/csharp/BasicUsage/InstanceLog.cs | Adds snippet source for instance/field-based logger usage. |
| docs/core/extensions/logging/snippets/source-generation/csharp/BasicUsage/PrimaryCtorLog.cs | Adds snippet source for primary-constructor logger usage. |
| docs/core/extensions/logging/snippets/source-generation/csharp/BasicUsage/DynamicLog.cs | Adds snippet source for dynamic log level usage. |
| docs/core/extensions/logging/snippets/source-generation/csharp/LogMethodAnatomy/LogMethods.cs | Adds snippet source for a “valid log method” example. |
| docs/core/extensions/logging/snippets/source-generation/csharp/LogMethodAnatomy/IndeterminateOrder.cs | Adds snippet source for indeterminate parameter ordering example. |
| docs/core/extensions/logging/snippets/source-generation/csharp/LogMethodAnatomy/CaseInsensitiveExample.cs | Adds snippet source for case-insensitive template name support example. |
| docs/core/extensions/logging/snippets/source-generation/csharp/MoreLoggingExamples/LoggingSample.cs | Adds snippet source for additional logging examples section. |
| docs/core/extensions/logging/snippets/source-generation/csharp/RedactingSensitiveInformation/RedactionSetup.cs | Adds self-contained redaction setup snippet (taxonomy, attribute, and redactor). |
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
| [LoggerMessage(0, LogLevel.Information, "User SSN: {SSN}")] | ||
| public static partial void LogPrivateInformation( | ||
| this ILogger logger, | ||
| [MyTaxonomyClassifications.Private] string SSN); |
There was a problem hiding this comment.
This is incorrect as reported in #54570
[MyTaxonomyClassifications.Private]
There was a problem hiding this comment.
Hi @laicasaane this does work, it's resolving to PrivateAttribute, even though you type in Private. We have a compiler running as an action that compiles the code snippets and blocks the PR if it won't compile.
I think the reason why it didn't work for you was because you were working with an incomplete snippet and had to cobble it together and you were just missing the actual attribute definition.
Summary
Fixes #54570
Internal previews