-
Notifications
You must be signed in to change notification settings - Fork 6k
Add console logger breaking changes #19739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76f4356
add console logger breaking change
gewarren 21a4476
lint
gewarren 000d729
review on staging
gewarren 3391579
Make xrefs consistent
gewarren 88b20a5
Add ConsoleFormatterOptions type
gewarren 5ce3a18
pull upstream master
gewarren d0e38b2
Merge branch 'consoleloggeroptions' of github.com:gewarren/docs into …
gewarren 8d51668
fix up bad merge
gewarren ed060b3
pull upstream master
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
includes/core-changes/corefx/5.0/obsolete-consoleloggeroptions-properties.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
### Obsolete properties on ConsoleLoggerOptions | ||
|
||
The <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat?displayProperty=nameWithType> type and some properties on <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions> are now obsolete. | ||
|
||
#### Change description | ||
|
||
Starting in .NET 5.0, the <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat?displayProperty=nameWithType> type and several properties on <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions> are obsolete. The obsolete properties are: | ||
|
||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.DisableColors?displayProperty=nameWithType> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.IncludeScopes?displayProperty=nameWithType> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.TimestampFormat?displayProperty=nameWithType> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.UseUtcTimestamp?displayProperty=nameWithType> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format?displayProperty=nameWithType> | ||
|
||
With the introduction of new formatters, these properties are now available on the individual formatters. | ||
|
||
#### Reason for change | ||
|
||
The <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format> property is an enumeration type, which cannot represent a custom formatter. | ||
|
||
The remaining properties were set on <xref:Microsoft.Extensions.Logging.Console.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 Preview 8 | ||
|
||
#### Recommended action | ||
|
||
- Use the new <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.FormatterName?displayProperty=nameWithType> property in place of the <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format?displayProperty=nameWithType> property. For example: | ||
|
||
```csharp | ||
loggingBuilder.AddConsole(options => | ||
{ | ||
options.FormatterName = ConsoleFormatterNames.Systemd; | ||
}); | ||
``` | ||
|
||
There are several differences between <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.FormatterName> and <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format>: | ||
|
||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format> has only two possible options: `Default` and `Systemd`. | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.FormatterName> is case insensitive and can be any string. The reserved, built-in names are `Simple`, `Systemd`, and `Json` (.NET 5.0 and later). | ||
- `"Format": "Systemd"` maps to `"FormatterName": "Systemd"`. | ||
- `"Format": "Default"` maps to `"FormatterName": "Simple"`. | ||
|
||
- For the <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.DisableColors>, <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.IncludeScopes>, <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.TimestampFormat>, and <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.UseUtcTimestamp> properties, use the corresponding property on the new <xref:Microsoft.Extensions.Logging.Console.ConsoleFormatterOptions>, <xref:Microsoft.Extensions.Logging.Console.JsonConsoleFormatterOptions>, or <xref:Microsoft.Extensions.Logging.Console.SimpleConsoleFormatterOptions> types instead. For example: | ||
|
||
```csharp | ||
loggingBuilder.AddSimpleConsole(options => | ||
{ | ||
options.DisableColors = true; | ||
}); | ||
``` | ||
|
||
The following two JSON snippets show how the configuration file changes. Old configuration file: | ||
|
||
```json | ||
{ | ||
"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: | ||
|
||
```json | ||
{ | ||
"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": "*" | ||
} | ||
``` | ||
|
||
#### Category | ||
|
||
- Core .NET libraries | ||
- ASP.NET | ||
|
||
#### Affected APIs | ||
|
||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.DisableColors?displayProperty=fullName> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.IncludeScopes?displayProperty=fullName> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.TimestampFormat?displayProperty=fullName> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.UseUtcTimestamp?displayProperty=fullName> | ||
- <xref:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format?displayProperty=fullName> | ||
|
||
<!-- | ||
|
||
#### Affected APIs | ||
|
||
- `P:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.DisableColors` | ||
- `P:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.IncludeScopes` | ||
- `P:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.TimestampFormat` | ||
- `P:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.UseUtcTimestamp` | ||
- `P:Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions.Format` | ||
|
||
--> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.