ANSI terminal themes; culture-specific formatting #38
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.
Fixes #8, fixes #19.
Theming is implemented by the
TemplateTheme
class; built-in themes areTemplateTheme.Code
,TemplateTheme.Grayscale
, andTemplateTheme.Literate
, which were lifted directly from Serilog.Sinks.Console.Themes can be user-specified, and can inherit from a "base" theme:
Produces:
(LOL 😁)
Only ANSI escape sequence-based theming is supported (so on Windows, only recent versions of the console will support them, along with Windows Terminal).
Themed message template rendering touched on support for
IFormatProvider
, so I've rolled in those changes, too.There's minor API breakage, with optional or nullable
IFormatProvider
arguments added to the variousSerilogExpression
factory methods, and optional/nullableTemplateTheme
arguments added to theExpressionTemplate
constructors/factory methods.Fun twist - since the same templating implementation is used for text and JSON output, you can also do this:
Perf impact shouldn't be huge, and since more work is brought back to template "compile" time (there are no runtime dictionary lookups), I'm expecting that theming will be slightly faster here than in Serilog.Sinks.Console, but that's for another day.
Tests are also a bit light, but the code paths covered by themed and un-themed output are identical apart from the behavior implemented in the (tiny)
Style
andStyleReset
structs, so I think I can get away with it 😉