Skip to content
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

Allow colorized custom formatters by exposing TextWriterExtensions #44582

Closed
ramondeklein opened this issue Nov 12, 2020 · 7 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-Logging untriaged New issue has not been triaged by the area owner

Comments

@ramondeklein
Copy link

Background and Motivation

.NET Core 5 supports using custom console formatters, which is great to customize the logging output. Using colors is very useful for console logging to highlight important events, but each custom formatter needs to implement this.

The BCL already has a very useful TextWriterExtensions that implements colorized output, but it's internal and can't be used for custom formatters. Making this class public would make it much easier to implement a custom formatter that uses colors the correct way.

Proposed API

Make Microsoft.Extensions.Logging.Console.TextWriterExtensions public or make the AnsiParser accessible.

@ramondeklein ramondeklein added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 12, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Nov 12, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ramondeklein
Copy link
Author

ramondeklein commented Nov 12, 2020

@ericstj I suggest adding the area-Extensions-Logging label. I can create a PR for this if you consider this suggestion.

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Nov 12, 2020

Closely related to #44513.

@ghost
Copy link

ghost commented Nov 12, 2020

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.


Issue meta data
Issue content:
## Background and Motivation

.NET Core 5 supports using custom console formatters, which is great to customize the logging output. Using colors is very useful for console logging to highlight important events, but each custom formatter needs to implement this.

The BCL already has a very useful TextWriterExtensions that implements colorized output, but it's internal and can't be used for custom formatters. Making this class public would make it much easier to implement a custom formatter that uses colors the correct way.

Proposed API

Make Microsoft.Extensions.Logging.Console.TextWriterExtensions public or make the AnsiParser accessible.

</td>
Issue author: ramondeklein
Assignees: -
Labels:
`api-suggestion`, `area-Extensions-Logging`, `untriaged`

</td>
Milestone: -

@maryamariyan
Copy link
Member

maryamariyan commented Nov 12, 2020

Thanks @ramondeklein as @SingleAccretion recommended, because of #44513, we'd want to preferably first expose some common APIs which fit better into System.Console and remove logic out of Logging.Console accordingly. That is why we decided not to make color specific formatting and Ansi parsing APIs public in Logging.Console as it might not be the right place for it.

Until those APIs are available, what I would do for custom formatting that would support colors, is to use the template gist I shared in the comment here, which basically just duplicates the same TextWriterExtensions code you shared above.

If any such TextWriterExtensions APIs are needed to become public I think they should live in System.Console instead not in Logging.Console.

cc @eerhardt perhaps we could dupe this as part of #44513 as well?

@maryamariyan
Copy link
Member

This is a supporting case for adding those general ANSI APIs in System.Console. Closing as dupe.

@maryamariyan
Copy link
Member

Note for future, there is a doc related to this topic: https://docs.microsoft.com/en-us/dotnet/core/extensions/console-log-formatter

@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-Logging untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants