Skip to content

Conversation

@snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Sep 28, 2025

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")

@snakefoot snakefoot added the enhancement Improvement on existing feature label Sep 28, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
NullTarget runtime state
src/NLog/Targets/NullTarget.cs
Added private fields _logEventCounter, _lastMesageBuilder, _lastLogEvent; added public getters LogEventCounter, LastMessage, LastLogEvent; updated Write to increment counter and, when FormatMessage is true, store the event and render the message into a reusable StringBuilder.
Unit test adjustments
tests/NLog.UnitTests/LayoutRenderers/AllEventPropertiesTests.cs
Replaced DebugTarget with NullTarget in the IncludeScopeProperties test and instantiated it with FormatMessage = true; updated target retrieval/cast to NullTarget.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A whisk of logs, a silent burrow’s glow,
I count each hop—one, two, in tidy row.
Last nibble saved, the message tucked just right,
A carrot of state in moonlit byte-night.
Shh—no prints, no fuss, just trails I know. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request has no description, so it does not convey any details about the changeset and therefore fails to meet the requirement for a related description. Please add a pull request description that briefly summarizes the key changes—such as the addition of runtime state tracking properties and lazy message rendering in NullTarget when FormatMessage is true—to help reviewers understand the intent and scope of this enhancement.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly identifies the affected class (NullTarget) and concisely describes the primary change (avoiding upfront string allocation when FormatMessage is enabled), accurately reflecting the main optimization introduced in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@snakefoot snakefoot force-pushed the dev branch 2 times, most recently from 75028e7 to d4c7f7c Compare September 28, 2025 17:55
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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4c7f7c and 3ea7e39.

📒 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

@sonarqubecloud
Copy link

@snakefoot snakefoot disabled auto-merge September 28, 2025 18:49
@snakefoot snakefoot merged commit acbf8b2 into NLog:dev Sep 28, 2025
5 of 6 checks passed
@snakefoot snakefoot added this to the 6.0.5 milestone Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement on existing feature size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant