Obsolete properties on ConsoleLoggerOptions

The Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat type and some properties on ConsoleLoggerOptions are now obsolete.

Change description

Starting in .NET 5, the Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat type and several properties on ConsoleLoggerOptions are obsolete. The obsolete properties are:

With the introduction of new formatters, these properties are now available on the individual formatters.

Reason for change

The Format property is an enumeration type, which cannot represent a custom formatter.

The remaining properties were set on ConsoleLoggerOptions and applied to both of the built-in formats for console logs. However, with the introduction of a new formatter API, it makes more sense for formatting to be represented on the formatter-specific options. This change provides better separation between the logger and logger formatters.

Version introduced

5.0

The following two JSON snippets show how the configuration file changes. Old configuration file:

{
  "Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },

    "Console": {
      "LogLevel": {
        "Default": "Information"
      },
      "Format": "Systemd",
      "IncludeScopes": true,
      "TimestampFormat": "HH:mm:ss",
      "UseUtcTimestamp": true
    }
  },
  "AllowedHosts": "*"
}

New configuration file:

{
  "Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },

    "Console": {
      "LogLevel": {
        "Default": "Information"
      },
      "FormatterName": "Systemd",
      "FormatterOptions": {
        "IncludeScopes": true,
        "TimestampFormat": "HH:mm:ss",
        "UseUtcTimestamp": true
      }
    }
  },
  "AllowedHosts": "*"
}

Affected APIs