Skip to content

Code snippet provided in documentation does not compile #32035

Closed
@ign3u5

Description

@ign3u5

Issue description

The documentation for compile-time logging source generation contains the following code snippet:

using System.Text.Json;
using Microsoft.Extensions.Logging;

ILogger<SampleObject> logger = LoggerFactory.Create(
    builder =>
    builder.AddJsonConsole(
        options =>
        options.JsonWriterOptions = new JsonWriterOptions()
        {
            Indented = true
        }))
    .CreateLogger<SampleObject>();

logger.CustomLogEvent(LogLevel.Information, "Liana", "Seattle");

public static partial class SampleObject
{
    [LoggerMessage(EventId = 23)]
    public static partial void CustomLogEvent(
        this ILogger logger, LogLevel logLevel,
        string name, string city);
}

This code does not compile due to it using a static class as a generic type argument. Even without this, no logs will appear in the console as the LoggerFactory is not properly disposed of and therefore the logs are not flushed.

Metadata

Metadata

Assignees

Labels

dotnet-fundamentals/svchelp wantedGood for community contributors to help [up-for-grabs]okr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions