Skip to content

Obsolete properties on ConsoleLoggerOptions #19533

@shirhatti

Description

@shirhatti

Obsolete properties on ConsoleLoggerOptions

As part of the changes introduced in dotnet/runtime#38616, some properties present on ConsoleLoggerOptions have been obsoleted. With the introduction on new formatters, these properties now live on the individual formatters.

The properties obsoleted are:

  • DisableColors

  • IncludeScopes

  • TimestampFormat

  • UseUtcTimestamp

  • Format

Version introduced

Any application targeting a version >= 5.0.0-preview8 of the Microsoft.Extensions.Logging.Console NuGet package or any application targeting a version >= 5.0.0-preview8 of the Microsoft.AspNetCore.App shared framework.

Old behavior

N/A. Old APIs still work. They have marked obsolete for deletion in a future release.

New behavior

N/A

Reason for change

The Format property was a enum. An enum doesn't work well anymore given that it can't represent custom formatters.

The remaining properties were set on the ConsoleLoggerOptions and applied to both the inbuilt formats for Console logs. However, with introduction of a new formatter API, it makes more sense for formatting concerns to be represented on the formatter-specific options. The new change better represent the separation of concerns between the logger and loggerformatters.

Recommended action

The Format property has now been replaced by the FormatterName property.

loggingBuilder.AddConsole(options =>
{
-    options.Format = ConsoleLoggerFormat.Systemd;
+  options.FormatterName = ConsoleFormatterNames.Systemd;
});

These properties are now set on the individual formatter options. In the case of the in-built formatters, the types are:

  • Microsoft.Extensions.Logging.Console.JsonConsoleFormatterOptions
  • Microsoft.Extensions.Logging.Console.SimpleConsoleFormatterOptions

Assuming you're using the SimpleConsoleFormatter, instead of setting the DisableColors property on the ConsoleLoggerOptions

loggingBuilder.AddConsole(options =>
{
    options.DisableColors = true;
});

you would now set it on the SimpleConsoleFormatterOptions

(edited by gewarren here)

loggingBuilder.AddSimpleConsole(options =>
{
    options.ColorBehavior = LoggerColorBehavior.Disabled;
});

Category

  • ASP.NET Core
  • Core .NET libraries

Affected APIs


Issue metadata

  • Issue type: breaking-change

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 5Work items for the .NET 5 releasebreaking-changeIndicates a .NET Core breaking change

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions