Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Documentation focused on LoggerMessage.Define() from .NET Core 3.x era. Modern .NET 6+ applications should use LoggerMessageAttribute with compile-time source generation for better performance and developer experience.

Changes

Restructured content hierarchy:

  • Source-generated logging (LoggerMessageAttribute) now primary approach
  • Legacy LoggerMessage.Define() moved to dedicated section for .NET Framework/Core 3.1 users
  • Added benefits summary with concrete performance advantages (compile-time parsing, zero boxing, unlimited parameters)

Updated all examples:

Before (legacy):

public static class LoggerExtensions
{
    private static readonly Action<ILogger, WorkItem, Exception> s_processingPriorityItem;
    
    static LoggerExtensions()
    {
        s_processingPriorityItem = LoggerMessage.Define<WorkItem>(
            LogLevel.Information,
            new EventId(1, nameof(PriorityItemProcessed)),
            "Processing priority item: {Item}");
    }
    
    public static void PriorityItemProcessed(this ILogger logger, WorkItem workItem) =>
        s_processingPriorityItem(logger, workItem, default!);
}

After (modern):

public static partial class Log
{
    [LoggerMessage(
        EventId = 1,
        Level = LogLevel.Information,
        Message = "Processing priority item: {Item}")]
    public static partial void PriorityItemProcessed(
        ILogger logger, WorkItem item);
}

Cross-references:

  • Added links to compile-time logging source generation documentation
  • Scope examples use BeginScope with source-generated methods
  • Legacy section explains migration path and limitations (6 parameter limit, no dynamic log level)
Original prompt

This section details on the original issue you should resolve

<issue_title>update LoggerMessage.Define() to be source generated logging</issue_title>
<issue_description>### Type of issue

Outdated article

Description

Most of the content on that high perf logging page talks about LoggerMessage.Define() which may have been state of the art around .NET Core 3 but as soon as source generated logging came out. Please update this documentation to reflect the above.

Page URL

https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging#define-a-logger-message

Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/extensions/high-performance-logging.md

Document Version Independent Id

3f5f1b6e-06ac-cc07-48cd-b8b957a4abbb

Article author

@IEvangelist

Metadata

  • ID: aa00c051-c047-bbcd-5e25-ca6a722b51c3
  • Service: dotnet-fundamentals</issue_description>

Comments on the Issue (you are @copilot in this section)

@tarekgh We may need to copy the summary from the page https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator#summary and refer to the page too.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update LoggerMessage.Define() for source generated logging Modernize high-performance logging docs to prioritize source-generated logging Jan 28, 2026
Copilot AI requested a review from gewarren January 28, 2026 23:17
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.

update LoggerMessage.Define() to be source generated logging

2 participants