-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add pretty-print JSON support to RichTextBox sink #38
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
Conversation
Introduces pretty-printing for JSON output in the RichTextBox sink, controlled via new options.
Updates the package version to 3.2.0. Adds integration tests for empty collections, dictionaries with null and non-string keys, and scalar/non-formattable objects.
Enhanced LevelTokenRenderer to gracefully handle invalid log level indices and expanded test coverage for various level formatting scenarios. Also cleaned up unused usings and removed redundant tests in TokenRendererTests.
Update funding config and improve README support section Corrected the Ko-fi key in FUNDING.yml. Refactored the README to clarify support options, improve FAQ answers, and reorganize contribution and support sections for better readability.
ddd3472 to
9867081
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for JSON pretty-printing in log messages, enabling better readability of structured data in the WinForms RichTextBox sink. The version has been bumped from 3.1.3 to 3.2.0 to reflect this new feature.
Key changes:
- Added three new configuration options:
prettyPrintJson,indentSize, anduseSpacesForIndentto control JSON formatting - Enhanced
ValueFormatterStatewith indentation tracking capabilities - Refactored JSON and display value formatters to support both compact and pretty-printed output
- Improved bounds checking in
LevelTokenRendererto handle invalid log levels more gracefully
Reviewed Changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| RichTextBoxSinkOptions.cs | Added three new properties for JSON pretty-printing configuration |
| RichTextBoxSink.cs | Updated to pass options to the renderer |
| TemplateRenderer.cs | Modified to propagate options to token renderers |
| MessageTemplateTokenRenderer.cs | Updated to pass options to value formatters |
| PropertiesTokenRenderer.cs | Updated to pass options to value formatters |
| ValueFormatterState.cs | Added indentation tracking fields and helper methods |
| ValueFormatter.cs | Added extensibility point for initial state creation |
| JsonValueFormatter.cs | Implemented pretty-printing logic with indentation support |
| DisplayValueFormatter.cs | Updated to forward pretty-print settings to JsonValueFormatter |
| LevelTokenRenderer.cs | Moved bounds checking from GetLevelMoniker to Render method |
| RichTextBoxSinkLoggerConfigurationExtensions.cs | Added pretty-print parameters to extension methods |
| JsonFormattingTests.cs | Added comprehensive tests for pretty-printing feature |
| TokenRendererTests.cs | New test file for token renderer coverage |
| RichTextBoxSinkTestBase.cs | Added overload accepting RichTextBoxSinkOptions |
| Serilog.Sinks.RichTextBox.WinForms.Colored.csproj | Updated version to 3.2.0 and release notes |
| .github/workflows/build.yml | Updated GitHub Actions versions and coverage threshold |
| README.md | Updated feature list and support section |
| Demo/Form1.cs & Form1.Designer.cs | Added UI toggle for pretty-print feature |
| SECURITY.md, CODE_OF_CONDUCT.md | Updated email address format |
| Various test files | Removed unnecessary comments for cleaner code |
Files not reviewed (1)
- Demo/Form1.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...g.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Formatting/JsonValueFormatter.cs
Outdated
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSinkOptions.cs
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored/RichTextBoxSinkLoggerConfigurationExtensions.cs
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored/Serilog.Sinks.RichTextBox.WinForms.Colored.csproj
Outdated
Show resolved
Hide resolved
....Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Formatting/ValueFormatterState.cs
Outdated
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored.Test/Integration/TokenRendererTests.cs
Outdated
Show resolved
Hide resolved
Refines JSON pretty printing to respect indent size for both spaces and tabs, adds validation to restrict indent size between 1 and 16, and updates related tests and documentation. Also optimizes JSON string escaping and clarifies parameter descriptions.
Replaces the previous indentSize and useSpacesForIndent options with a single spacesPerIndent parameter, enforcing space-based indentation for pretty-printed JSON. Updates all related constructors, method signatures, and tests to reflect this change, simplifying configuration and code paths.
Removed the option to use tabs for JSON pretty printing and standardized on spaces for indentation. Updated constructors and internal logic in DisplayValueFormatter and JsonValueFormatter to use spacesPerIndent only. Also removed the related test case from JsonFormattingTests.
Introduces a numeric up/down control in the demo form to allow users to set the number of spaces per indentation level for pretty-printed JSON (0-16, default 2). Updates the logger and sink configuration to use the selected indent size. Also changes the default indent from 4 to 2 in the sink options and extension method.
ddb9a2f to
03852f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 27 out of 28 changed files in this pull request and generated 8 comments.
Files not reviewed (1)
- Demo/Form1.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...inks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Formatting/DisplayValueFormatter.cs
Outdated
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSinkOptions.cs
Show resolved
Hide resolved
...nks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Rendering/PropertiesTokenRenderer.cs
Outdated
Show resolved
Hide resolved
...ichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Rendering/MessageTemplateTokenRenderer.cs
Outdated
Show resolved
Hide resolved
Serilog.Sinks.RichTextBox.WinForms.Colored/RichTextBoxSinkLoggerConfigurationExtensions.cs
Outdated
Show resolved
Hide resolved
...g.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Formatting/JsonValueFormatter.cs
Outdated
Show resolved
Hide resolved
Refactored all token renderer and TemplateRenderer constructors to accept a RichTextBoxSinkOptions object instead of individual parameters. Updated tests and extension methods accordingly. Standardized default JSON indentation to 2 spaces and removed unused parameters for consistency.
Updated DisplayValueFormatter, JsonValueFormatter, and ValueFormatter to accept a RichTextBoxSinkOptions object instead of individual parameters. Updated all usages and internal references to use the options object, improving maintainability and consistency.
Removed obsolete parameters from StructureValue and ValueFormatterState constructors to align with updated Serilog API.
Introduces pretty-printing for JSON output in the RichTextBox sink, controlled via new options.
Motivation and Context
See #37