Skip to content

Example of implementing a custom logging provider doesn't match .NET 7 #37046

@SetTrend

Description

@SetTrend

Trying to reproduce the example from the page, I noticed that the following code snippet doesn't apply to .NET 7:

public static ILoggingBuilder AddColorConsoleLogger(this ILoggingBuilder builder)
  {
    builder.AddConfiguration();

    builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, ColorConsoleLoggerProvider>());

    LoggerProviderOptions.RegisterProviderOptions<ColorConsoleLoggerConfiguration, ColorConsoleLoggerProvider>builder.Services);

    return builder;
  }

Reasoning

  1. There is no extension method adorning the ILoggingBuilder interface with a parameterless AddConfiguration() member:
    AddConfiguration
  2. builder.Services doesn't provide a TryAddEnumerable method.
  3. Where does LoggerProviderOptions all of a sudden come from?

In addition to these issues, the page is missing an explanation on how to retrieve the configured logging level when it may be defined in Default or the custom logger's dedicated configuration section (https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/#configure-logging)


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 169717

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-fundamentals/svcneeds-more-infoNeeds more info from OP. Auto-closed after 2 weeks if no response. [org][resolution]

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions