Skip to content

Logging source generator generates uncompilable code for new .NET Framework project  #83393

@stephentoub

Description

@stephentoub

Same issue as #83392, but for the logging source generator rather than for the JSON source generator.

Repro:

  1. Create a new .NET Framework 4.8 console app.
  2. Add a nuget reference to the latest stable Microsoft.Extensions.Logging.Abstractions nuget package.
  3. Paste this code into your Program.cs, which is based on the docs for [LoggerMessage]:
using Microsoft.Extensions.Logging;

internal partial class Program
{
    static void Main() { }

    [LoggerMessage(
        EventId = 0,
        Level = LogLevel.Critical,
        Message = "Could not open socket to `{hostName}`")]
    static partial void CouldNotOpenSocket(ILogger logger, string hostName);
}
  1. Compile. You'll get errors like this:
1>ConsoleApp7\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(7,148,7,149): error CS8370: Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

To my knowledge, the only fix is to change your project's language version to something >= 8.0, which is officially an unsupported configuration.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions