Skip to content

Conversation

@vonhoff
Copy link
Owner

@vonhoff vonhoff commented Nov 9, 2025

Introduces pretty-printing for JSON output in the RichTextBox sink, controlled via new options.

Motivation and Context

See #37

Introduces pretty-printing for JSON output in the RichTextBox sink, controlled via new options.
@vonhoff vonhoff linked an issue Nov 9, 2025 that may be closed by this pull request
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.
@vonhoff vonhoff force-pushed the 37-feat-toggle-for-json-pretty-printing branch from ddd3472 to 9867081 Compare November 9, 2025 14:44
@vonhoff vonhoff requested a review from Copilot November 9, 2025 15:13
Copy link

Copilot AI left a 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, and useSpacesForIndent to control JSON formatting
  • Enhanced ValueFormatterState with indentation tracking capabilities
  • Refactored JSON and display value formatters to support both compact and pretty-printed output
  • Improved bounds checking in LevelTokenRenderer to 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.

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.
@vonhoff vonhoff force-pushed the 37-feat-toggle-for-json-pretty-printing branch from ddb9a2f to 03852f4 Compare November 9, 2025 16:28
@vonhoff vonhoff requested a review from Copilot November 9, 2025 17:02
Copy link

Copilot AI left a 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.

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.
@vonhoff vonhoff merged commit ab12a57 into master Nov 10, 2025
1 check passed
@vonhoff vonhoff deleted the 37-feat-toggle-for-json-pretty-printing branch November 10, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Toggle for JSON pretty printing

2 participants