JsonLayout - Reduce code complexity for rendering JsonAttribute#6026
JsonLayout - Reduce code complexity for rendering JsonAttribute#6026
Conversation
WalkthroughRefactors JSON layout value rendering by introducing a helper to centralize rendering and non-empty checks, adjusts control flow for encode/no-encode paths, simplifies escaping, and updates decision points based on StringBuilder length. Removes an obsolete escape helper and narrows a serializer method’s visibility without changing public APIs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Logger
participant JsonLayout
participant JsonAttribute
participant Serializer as DefaultJsonSerializer
Logger->>JsonLayout: RenderJsonFormattedMessage(logEvent)
JsonLayout->>JsonLayout: AppendJsonPropertyValue(...)
alt Encode = false
JsonLayout->>JsonAttribute: RenderAppendJsonValue(logEvent, sb, valueStart)
JsonAttribute-->>JsonLayout: success/failure via sb length
opt Failure
JsonLayout->>JsonLayout: Revert sb to original length
end
else Encode = true
alt ValueType is null (string path)
JsonLayout->>JsonAttribute: RenderAppendJsonValue(logEvent, sb, valueStart)
JsonLayout->>Serializer: PerformJsonEscapeWhenNeeded(sb, startPos, escapeUnicode)
Serializer-->>JsonLayout: Escaped (if needed)
JsonLayout->>JsonLayout: Append quotes using valueStart
else Object value present
JsonLayout->>JsonLayout: Previous object handling preserved
JsonLayout->>Serializer: PerformJsonEscapeWhenNeeded (if string-like)
end
end
JsonLayout-->>Logger: JSON output (sb)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (2)src/NLog/Layouts/JSON/JsonAttribute.cs (2)
src/NLog/Layouts/JSON/JsonLayout.cs (2)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|



No description provided.