Skip to content

JsonLayout - Changed SuppressSpaces to default true#5781

Merged
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:JsonSpaces
Apr 13, 2025
Merged

JsonLayout - Changed SuppressSpaces to default true#5781
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:JsonSpaces

Conversation

@snakefoot
Copy link
Contributor

Resolves #5772

@snakefoot snakefoot added json / json-layout breaking behavior change Same API, different result new default (breaking) Kind of Breaking behavior change labels Apr 13, 2025
@snakefoot snakefoot added this to the 6.0 milestone Apr 13, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 13, 2025

Walkthrough

This pull request adapts JSON output formatting in several NLog components. The key modifications include setting the default for the SuppressSpaces property to true in JSON layout and serializer classes, updating XML documentation to reflect these defaults, and refining the control flow so that enabling indenting disables space suppression. In addition, a new JsonConverterWithSpaces class is introduced to wrap default JSON converters based on their type. Unit tests have been updated to expect compact JSON output with no extraneous spaces.

Changes

File(s) Change Summary
src/NLog/Layouts/JSON/JsonArrayLayout.cs
src/NLog/Layouts/JSON/JsonLayout.cs
Updated SuppressSpaces to default to true and enhanced XML documentation. In JsonLayout.cs, adjusted logic so that setting IndentJson to true automatically sets SuppressSpaces to false and refined JSON formatting strings.
src/NLog/Targets/DefaultJsonSerializer.cs
src/NLog/Targets/JsonSerializeOptions.cs
Replaced the boolean flag with a jsonPropertyDelimeter in serializer logic to conditionally include spaces. Added a new SuppressSpaces property (defaulting to true) in JsonSerializeOptions and updated XML documentation for properties including default values.
src/NLog/MessageTemplates/ValueFormatter.cs Introduced the new nested class JsonConverterWithSpaces and modified the getter for JsonConverter to conditionally wrap instances (e.g., when of type DefaultJsonSerializer) for enhanced serialization control.
Tests (tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs,
tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs,
tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs,
tests/NLog.UnitTests/LoggerTests.cs,
tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs,
tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs)
Updated expected JSON output in assertions to reflect a compact format without extra spaces. Additionally, modified logger configuration in one test to explicitly set suppressSpaces='false'.

Sequence Diagram(s)

sequenceDiagram
    participant L as Logger
    participant JL as JsonLayout
    L->>JL: Set IndentJson = true
    Note right of JL: Check IndentJson property
    JL-->>JL: Set SuppressSpaces = false
    JL->>L: Render compact JSON with indenting adjustments
Loading
sequenceDiagram
    participant VF as ValueFormatter
    participant SC as ServiceContainer
    participant JC as IJsonConverter
    participant JCS as JsonConverterWithSpaces
    VF->>SC: Retrieve IJsonConverter instance
    SC-->>VF: Return jsonConverter instance
    VF->>JCS: Call CreateJsonConverter(jsonConverter)
    alt jsonConverter is DefaultJsonSerializer
        JCS-->>VF: Return wrapped JsonConverterWithSpaces
    else
        JCS-->>VF: Return original jsonConverter
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Change JsonLayout to not include spaces by default for NLog v6 (#5772)

Poem

I'm a rabbit in the code, so spry,
Hopping through JSON with a keen eye.
Spaces suppressed, neat and tight,
Compact output brings delight.
Celebrate the change with a happy byte!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cddd8b and 32476b1.

📒 Files selected for processing (14)
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs (1 hunks)
  • src/NLog/Layouts/JSON/JsonLayout.cs (7 hunks)
  • src/NLog/MessageTemplates/ValueFormatter.cs (1 hunks)
  • src/NLog/Targets/DefaultJsonSerializer.cs (3 hunks)
  • src/NLog/Targets/JsonSerializeOptions.cs (2 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs (1 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs (1 hunks)
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs (2 hunks)
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs (4 hunks)
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs (22 hunks)
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs (8 hunks)
  • tests/NLog.UnitTests/LoggerTests.cs (3 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs (2 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs
  • src/NLog/Targets/DefaultJsonSerializer.cs
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs
  • tests/NLog.UnitTests/LoggerTests.cs
  • src/NLog/Layouts/JSON/JsonLayout.cs
  • src/NLog/Targets/JsonSerializeOptions.cs
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/NLog/MessageTemplates/ValueFormatter.cs (2)
src/NLog/Targets/DefaultJsonSerializer.cs (7)
  • DefaultJsonSerializer (47-757)
  • DefaultJsonSerializer (69-72)
  • SerializeObject (79-82)
  • SerializeObject (90-146)
  • SerializeObject (154-157)
  • SerializeObject (166-169)
  • SerializeObject (180-198)
src/NLog/Targets/JsonSerializeOptions.cs (1)
  • JsonSerializeOptions (42-98)
🔇 Additional comments (2)
src/NLog/MessageTemplates/ValueFormatter.cs (2)

57-57: Implementation maintains proper JSON formatting in message templates with updated default

The property implementation now utilizes the new JsonConverterWithSpaces.CreateJsonConverter method to wrap the JSON converter obtained from the service provider, ensuring consistent behavior with the updated defaults elsewhere in the codebase.


61-89: Well-implemented wrapper to preserve spacing in ValueFormatter context

This new class properly addresses the PR objective by ensuring that JSON serialization within message templates still includes spaces, even though the global default has been changed to suppress them. The implementation:

  1. Cleanly wraps DefaultJsonSerializer instances
  2. Sets SuppressSpaces = false explicitly for this context
  3. Handles exceptions differently with sanitized dictionary keys
  4. Maintains backward compatibility for message template formatting

This is a good pattern for overriding a global default in a specific context.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@snakefoot snakefoot force-pushed the JsonSpaces branch 2 times, most recently from 3ecc646 to f9f9c81 Compare April 13, 2025 09:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/NLog/MessageTemplates/ValueFormatter.cs (1)

61-84: Good implementation of the JsonConverterWithSpaces wrapper class

The wrapper class provides a clean solution to maintain spaces in ValueFormatter JSON output while allowing the default to be changed to SuppressSpaces=true globally. The implementation correctly handles both DefaultJsonSerializer and other converter types.

Consider adding a brief XML comment to explain why this class explicitly sets SuppressSpaces = false when the PR's main purpose is to change the default to true elsewhere, to help future maintainers understand this specific exception.

+        /// <summary>
+        /// Wrapper for JSON converters that ensures spaces are included in JSON output,
+        /// overriding the global default which suppresses spaces.
+        /// </summary>
         private sealed class JsonConverterWithSpaces : IJsonConverter
         {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ecc646 and f9f9c81.

📒 Files selected for processing (14)
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs (1 hunks)
  • src/NLog/Layouts/JSON/JsonLayout.cs (6 hunks)
  • src/NLog/MessageTemplates/ValueFormatter.cs (1 hunks)
  • src/NLog/Targets/DefaultJsonSerializer.cs (3 hunks)
  • src/NLog/Targets/JsonSerializeOptions.cs (2 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs (1 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs (1 hunks)
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs (2 hunks)
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs (4 hunks)
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs (22 hunks)
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs (4 hunks)
  • tests/NLog.UnitTests/LoggerTests.cs (3 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs (2 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs
🚧 Files skipped from review as they are similar to previous changes (11)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs
  • src/NLog/Targets/DefaultJsonSerializer.cs
  • src/NLog/Targets/JsonSerializeOptions.cs
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs
  • src/NLog/Layouts/JSON/JsonLayout.cs
  • tests/NLog.UnitTests/LoggerTests.cs
🔇 Additional comments (3)
tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs (2)

55-55: Good adaptation to the new default!

Great job setting SuppressSpaces = false explicitly in the test. This properly maintains the test's expected behavior after changing the default value to true in the JsonLayout class. The expected output on line 74 includes spaces in the JSON, which is ensured by this property setting.


157-157: Good consistency in XML configuration!

Correctly added the suppressSpaces='false' attribute to the XML configuration to match the code-based configuration change. This ensures that both test methods continue to work with the same JSON formatting style, maintaining consistency between the two test approaches.

src/NLog/MessageTemplates/ValueFormatter.cs (1)

55-58: The JsonConverter property now uses a wrapper to ensure spaces in JSON output

This change ensures that ValueFormatter still produces JSON with spaces (SuppressSpaces=false) while allowing the default to be changed to true elsewhere, maintaining readable output in message templates.

@snakefoot snakefoot force-pushed the JsonSpaces branch 2 times, most recently from f48ae93 to d6329ed Compare April 13, 2025 10:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/NLog/Layouts/JSON/JsonLayout.cs (1)

151-151: Optional: Allow indentation with selective spacing.
When IndentJson is enabled, _suppressSpaces is forced to false. Though likely intended, consider a scenario in which a user wants indentation but minimal spacing around property delimiters. You could add a user-facing override if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9f9c81 and d6329ed.

📒 Files selected for processing (14)
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs (1 hunks)
  • src/NLog/Layouts/JSON/JsonLayout.cs (6 hunks)
  • src/NLog/MessageTemplates/ValueFormatter.cs (1 hunks)
  • src/NLog/Targets/DefaultJsonSerializer.cs (3 hunks)
  • src/NLog/Targets/JsonSerializeOptions.cs (2 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs (1 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs (1 hunks)
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs (2 hunks)
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs (4 hunks)
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs (22 hunks)
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs (4 hunks)
  • tests/NLog.UnitTests/LoggerTests.cs (3 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs (2 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (12)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs
  • src/NLog/Targets/DefaultJsonSerializer.cs
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs
  • tests/NLog.UnitTests/LoggerTests.cs
  • src/NLog/Targets/JsonSerializeOptions.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/NLog/MessageTemplates/ValueFormatter.cs (2)
src/NLog/Targets/DefaultJsonSerializer.cs (7)
  • DefaultJsonSerializer (47-757)
  • DefaultJsonSerializer (69-72)
  • SerializeObject (79-82)
  • SerializeObject (90-146)
  • SerializeObject (154-157)
  • SerializeObject (166-169)
  • SerializeObject (180-198)
src/NLog/Targets/JsonSerializeOptions.cs (1)
  • JsonSerializeOptions (42-98)
🔇 Additional comments (6)
src/NLog/Layouts/JSON/JsonLayout.cs (4)

59-59: Use of SuppressSpaces in LimitRecursionJsonConvert instantiation looks good.
This properly initializes the custom JSON converter with the new parameter, aligning with the updated layout behavior.


76-80: Correctly passing suppressSpaces to _serializerOptions.
Including the SuppressSpaces parameter in this constructor ensures consistent behavior throughout the JSON serialization process. No immediate issues detected.


114-129: Documentation and default value consistency.
Marking the XML documentation to “Default: true” matches the initialization of _suppressSpaces = true; This alignment helps maintain clarity for users configuring JSON layouts.


383-386: New inline delimiters match the SuppressSpaces goal.
These default strings now exclude spaces, which is consistent with SuppressSpaces = true. The logic is straightforward and should produce more compact JSON.

src/NLog/MessageTemplates/ValueFormatter.cs (2)

55-58: Lazy initialization of JsonConverter is well-structured.
The property uses JsonConverterWithSpaces.CreateJsonConverter(...) to ensure any default or custom serializer is wrapped consistently. Implementation is clear and concise.


61-90: Verify forcing SuppressSpaces = false in JsonConverterWithSpaces.
This class always sets SuppressSpaces = false, potentially ignoring user configuration. If that’s intentional, it might be worth clarifying, as it differs from other defaults that allow true/false.

Do you want to confirm that no user-set “SuppressSpaces” option is overridden by this hard-coded false value? If needed, you could pass a parameter to preserve user preferences.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/NLog/MessageTemplates/ValueFormatter.cs (2)

61-89: Add XML documentation to explain the purpose of JsonConverterWithSpaces

The new JsonConverterWithSpaces class effectively forces SuppressSpaces = false regardless of global defaults. While the implementation is solid, adding XML documentation would clarify why this class exists and why it needs to override the default space suppression behavior.

+        /// <summary>
+        /// Wrapper for JSON converters that ensures spaces are not suppressed in value formatting,
+        /// maintaining consistent behavior for message templates even when the global default changes.
+        /// </summary>
         private sealed class JsonConverterWithSpaces : IJsonConverter
         {
             private readonly Targets.DefaultJsonSerializer _serializer;
             private readonly Targets.JsonSerializeOptions _serializerOptions;
             private readonly Targets.JsonSerializeOptions _exceptionSerializerOptions;
 
+            /// <summary>
+            /// Creates a JsonConverter that ensures spaces are not suppressed if the provided converter is DefaultJsonSerializer.
+            /// Otherwise, returns the original converter.
+            /// </summary>
+            /// <param name="jsonConverter">The original JSON converter from the service provider</param>
+            /// <returns>A converter that maintains spaces in JSON output</returns>
             public static IJsonConverter CreateJsonConverter(IJsonConverter jsonConverter)
             {
                 if (jsonConverter is Targets.DefaultJsonSerializer defaultJsonConverter)
                     return new JsonConverterWithSpaces(defaultJsonConverter);
                 else
                     return jsonConverter;
             }

75-80: Consider making space suppression configurable rather than hard-coded

The JsonConverterWithSpaces constructor hard-codes SuppressSpaces = false for both regular and exception serialization. Consider making this configurable if there are scenarios where ValueFormatter might need to follow the global default.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6329ed and 8cddd8b.

📒 Files selected for processing (14)
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs (1 hunks)
  • src/NLog/Layouts/JSON/JsonLayout.cs (7 hunks)
  • src/NLog/MessageTemplates/ValueFormatter.cs (1 hunks)
  • src/NLog/Targets/DefaultJsonSerializer.cs (3 hunks)
  • src/NLog/Targets/JsonSerializeOptions.cs (2 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs (1 hunks)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs (1 hunks)
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs (2 hunks)
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs (4 hunks)
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs (22 hunks)
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs (4 hunks)
  • tests/NLog.UnitTests/LoggerTests.cs (3 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs (2 hunks)
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • tests/NLog.UnitTests/LayoutRenderers/VariableLayoutRendererTests.cs
  • tests/NLog.UnitTests/Layouts/CompoundLayoutTests.cs
  • src/NLog/Targets/DefaultJsonSerializer.cs
  • tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerTestsBase.cs
  • src/NLog/Targets/JsonSerializeOptions.cs
  • tests/NLog.UnitTests/Layouts/JsonLayoutTests.cs
  • src/NLog/Layouts/JSON/JsonArrayLayout.cs
  • tests/NLog.UnitTests/Targets/DefaultJsonSerializerClassTests.cs
  • tests/NLog.UnitTests/Layouts/JsonArrayLayoutTests.cs
  • tests/NLog.UnitTests/LoggerTests.cs
  • tests/NLog.UnitTests/LogMessageFormatterTests.cs
  • src/NLog/Layouts/JSON/JsonLayout.cs
🔇 Additional comments (2)
src/NLog/MessageTemplates/ValueFormatter.cs (2)

55-58: Modification of JsonConverter property to use JsonConverterWithSpaces wrapper

The JsonConverter property now uses a wrapper class to ensure that spaces are not suppressed in ValueFormatter, even though the default for JsonLayout is changing to suppress spaces. This maintains backward compatibility for the message template formatting.


82-88: Method implements correct conditional serialization based on value type

The SerializeObject method correctly differentiates between exceptions and other objects, applying the appropriate serialization options for each case. This ensures consistent formatting while properly sanitizing dictionary keys for exceptions.

@snakefoot snakefoot force-pushed the JsonSpaces branch 2 times, most recently from 04b9a52 to 32476b1 Compare April 13, 2025 10:24
@sonarqubecloud
Copy link

@snakefoot snakefoot enabled auto-merge (squash) April 13, 2025 10:37
@snakefoot snakefoot merged commit 64bad89 into NLog:dev Apr 13, 2025
6 checks passed
ana1250 pushed a commit to ana1250/NLog that referenced this pull request Apr 24, 2025
@snakefoot
Copy link
Contributor Author

Updated wiki: https://github.com/NLog/NLog/wiki/JsonLayout

@snakefoot snakefoot added the documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) label Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking behavior change Same API, different result documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) json / json-layout needs documentation on wiki new default (breaking) Kind of Breaking behavior change size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change JsonLayout to not include spaces by default for NLog v6

1 participant