-
Notifications
You must be signed in to change notification settings - Fork 1.4k
EventProperties - Format Dictionary Properties correctly #6054
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
WalkthroughTryFormatToString now returns nullable Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/NLog/Internal/FormatHelper.cs(2 hunks)src/NLog/LayoutRenderers/EventPropertiesLayoutRenderer.cs(1 hunks)src/NLog/LayoutRenderers/FuncLayoutRenderer.cs(1 hunks)src/NLog/LayoutRenderers/GdcLayoutRenderer.cs(1 hunks)src/NLog/LayoutRenderers/ScopeContextPropertyLayoutRenderer.cs(1 hunks)src/NLog/Layouts/Typed/Layout.cs(1 hunks)tests/NLog.UnitTests/LayoutRenderers/EventPropertiesTests.cs(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/NLog/LayoutRenderers/ScopeContextPropertyLayoutRenderer.cs (1)
src/NLog/Internal/FormatHelper.cs (2)
FormatHelper(38-87)TryFormatToString(68-86)
src/NLog/LayoutRenderers/EventPropertiesLayoutRenderer.cs (1)
src/NLog/Internal/FormatHelper.cs (2)
FormatHelper(38-87)TryFormatToString(68-86)
src/NLog/LayoutRenderers/FuncLayoutRenderer.cs (1)
src/NLog/Internal/FormatHelper.cs (2)
FormatHelper(38-87)TryFormatToString(68-86)
src/NLog/Layouts/Typed/Layout.cs (1)
src/NLog/Internal/FormatHelper.cs (2)
FormatHelper(38-87)TryFormatToString(68-86)
src/NLog/LayoutRenderers/GdcLayoutRenderer.cs (1)
src/NLog/Internal/FormatHelper.cs (2)
FormatHelper(38-87)TryFormatToString(68-86)
src/NLog/Internal/FormatHelper.cs (2)
src/NLog/LayoutRenderers/LayoutRenderer.cs (1)
IFormatProvider(218-221)src/NLog/Internal/ExceptionMessageFormatProvider.cs (1)
IFormatProvider(80-83)
🔇 Additional comments (7)
src/NLog/LayoutRenderers/GdcLayoutRenderer.cs (1)
106-106: LGTM - Variable declaration updated for nullable return type.The change from explicit
stringtovaraccommodates the nullablestring?return type fromTryFormatToStringand maintains consistency with similar changes across other layout renderers.src/NLog/LayoutRenderers/EventPropertiesLayoutRenderer.cs (1)
142-142: LGTM - Consistent with nullable return type handling.The variable declaration change from explicit
stringtovarproperly handles the nullablestring?returned byTryFormatToString.src/NLog/Layouts/Typed/Layout.cs (1)
193-193: Essential fallback logic for non-formattable types.The added fallback chain (
?? objectValue?.ToString() ?? string.Empty) correctly handles the scenario whereTryFormatToStringreturnsnullfor complex objects that aren'tIFormattableorIConvertible(such asDictionary<string, string>). This ensures such objects still render via theirToString()implementation rather than being silently omitted.src/NLog/LayoutRenderers/FuncLayoutRenderer.cs (1)
109-109: LGTM - Consistent refactor across layout renderers.Type inference usage aligns with the updated
TryFormatToStringreturningstring?and maintains consistency with other layout renderer changes in this PR.src/NLog/LayoutRenderers/ScopeContextPropertyLayoutRenderer.cs (1)
96-96: LGTM - Aligned with nullable return type.The change to
varis consistent with similar updates across all layout renderers and correctly handles the nullablestring?return type.tests/NLog.UnitTests/LayoutRenderers/EventPropertiesTests.cs (1)
86-98: Good test coverage for dictionary property rendering.The test correctly validates that
Dictionary<string, string>properties render askey=valuepairs when using the event-properties layout renderer, providing coverage for the bug fix whereTryFormatToStringreturnsnullfor non-formattable complex types.src/NLog/Internal/FormatHelper.cs (1)
68-86: Core fix: Return null for non-formattable objects to signal complex formatting requirement.The updated logic correctly returns
nullfor objects that are neitherIFormattablenorIConvertible, withIFormattableandIConvertiblehandled directly, and null inputs returningstring.Empty. Verify that all callers ofTryFormatToStringthroughout the codebase properly handle the nullable return type and that Layout.cs line 193 provides appropriate fallback handling.
c43e61f to
d143227
Compare
|



Fix bug introduced with the change to nullable API. See also: #5809