NullTarget - Avoid string-allocation upfront when FormatMessage = true#6009
NullTarget - Avoid string-allocation upfront when FormatMessage = true#6009
Conversation
WalkthroughAdds runtime state tracking to NullTarget by counting writes and capturing the last processed LogEventInfo and the last rendered message when FormatMessage is true. Updates a unit test to use NullTarget with message formatting enabled instead of DebugTarget. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Logger
participant NT as NullTarget
participant SB as StringBuilder (internal)
App->>NT: Write(logEvent)
activate NT
NT->>NT: _logEventCounter++
alt FormatMessage == true
NT->>NT: _lastLogEvent = logEvent
NT->>SB: ensure builder and reset length
NT->>SB: render logEvent into builder
note right of NT #DDEBF7: LastMessage and LastLogEvent available via properties
else
note right of NT #F3F3F3: Only counter updated
end
deactivate NT
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
75028e7 to
d4c7f7c
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/NLog/Targets/NullTarget.cs(3 hunks)tests/NLog.UnitTests/LayoutRenderers/AllEventPropertiesTests.cs(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/NLog.UnitTests/LayoutRenderers/AllEventPropertiesTests.cs
🧰 Additional context used
🧬 Code graph analysis (1)
src/NLog/Targets/NullTarget.cs (3)
src/NLog/Targets/DebuggerTarget.cs (1)
Write(109-123)src/NLog/Layouts/Layout.cs (8)
Layout(105-108)Layout(116-119)Layout(127-144)Layout(149-155)Layout(163-170)Layout(382-412)Render(207-223)Render(231-248)src/NLog/LayoutRenderers/LayoutRenderer.cs (1)
Render(81-88)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: task-list-completed
|



Making NullTarget a better option for doing benchmarks of the NLog-engine.
Bonus goal would be to replace/obsolete DebugTarget, so "debug"-alias can be used for actual Debug-Target (Instead of "DebugSystem")