Skip to content

FileTarget - Adjust ArchiveSuffixFormat to better handle legacy ArchiveFileName#6065

Merged
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:FIleTargetRemoveNoise
Dec 21, 2025
Merged

FileTarget - Adjust ArchiveSuffixFormat to better handle legacy ArchiveFileName#6065
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:FIleTargetRemoveNoise

Conversation

@snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Dec 20, 2025

See also #6063

Adjusting the legacy-repair logic after it has been disturbed by the other legacy-repair-logic where ArchiveSuffixFormat containing {1 means that legacy ArchiveFileName is automatically activated. See also #5921

@snakefoot snakefoot added enhancement Improvement on existing feature file-target file-archiving Issues with archiving with the file target labels Dec 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 20, 2025

Walkthrough

The ArchiveSuffixFormat setter in FileTarget now guards legacy suffix stripping to run only when ArchiveFileName is a SimpleLayout with non-empty OriginalText, and it clears the internal archive handler cache by setting _fileArchiveHandler to null when the setter runs.

Changes

Cohort / File(s) Summary
Archive handler update
src/NLog/Targets/FileTarget.cs
ArchiveSuffixFormat setter: add guard so legacy suffix stripping runs only if ArchiveFileName is a SimpleLayout with non-empty OriginalText; add explanatory comment/example; reset _fileArchiveHandler to null to invalidate cached handler when suffix format changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the SimpleLayout type check and OriginalText emptiness check cover intended cases.
  • Confirm _fileArchiveHandler is reset in all code paths where ArchiveSuffixFormat changes.
  • Review the example comment for accuracy and clarity.

Poem

🐰 I hopped through suffixes, tidy and spry,
Cleared an old cache with a keen little eye,
Guarded the strip where text truly lives,
Now archives behave — neat tricks and small gives. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adjusting ArchiveSuffixFormat logic to better handle legacy ArchiveFileName in FileTarget.
Description check ✅ Passed The description is related to the changeset, referencing specific issues (#6063 and #5921) and explaining the adjustment to legacy-repair logic for ArchiveSuffixFormat.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a5f807 and 6082187.

📒 Files selected for processing (1)
  • src/NLog/Targets/FileTarget.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/NLog/Targets/FileTarget.cs (1)
src/NLog/Layouts/SimpleLayout.cs (5)
  • SimpleLayout (70-73)
  • SimpleLayout (79-82)
  • SimpleLayout (89-92)
  • SimpleLayout (100-104)
  • SimpleLayout (106-140)
⏰ 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
🔇 Additional comments (2)
src/NLog/Targets/FileTarget.cs (2)

441-450: LGTM! Guard condition improves legacy handling robustness.

The added guard ensures the legacy suffix stripping logic only runs when ArchiveFileName is a SimpleLayout with non-empty OriginalText. This correctly addresses the interaction issue mentioned in the PR objectives where ArchiveSuffixFormat containing "{1" was inappropriately triggering legacy ArchiveFileName activation.

The explanatory comment on line 444 helpfully illustrates the transformation (e.g., '{#}.log' + '_{0:00}' --> 01.log).


454-454: LGTM! Cache invalidation is correctly placed and consistent.

Setting _fileArchiveHandler = null ensures the cached archive handler is invalidated when ArchiveSuffixFormat changes, forcing recreation with the new suffix format on next access (line 480). This is consistent with the invalidation pattern used in other archive-related property setters throughout the class (lines 272, 293, 341, 359, 375).


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.

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/Targets/FileTarget.cs (1)

444-444: Optional: Clarify comment example.

The example is helpful, but note that {#} tokens are processed by the ArchiveFileName setter (lines 328-333) before this code executes. Consider rephrasing to reflect that this handles the case where ArchiveFileName has been stripped to just the extension, e.g., "After legacy {#} removal, ArchiveFileName = '.log' + ArchiveSuffixFormat = '_{0:00}' → '01.log'".

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 223695f and 9a5f807.

📒 Files selected for processing (1)
  • src/NLog/Targets/FileTarget.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/NLog/Targets/FileTarget.cs (1)
src/NLog/Layouts/SimpleLayout.cs (5)
  • SimpleLayout (70-73)
  • SimpleLayout (79-82)
  • SimpleLayout (89-92)
  • SimpleLayout (100-104)
  • SimpleLayout (106-140)
🔇 Additional comments (2)
src/NLog/Targets/FileTarget.cs (2)

441-450: LGTM: Guard refines legacy ArchiveFileName handling.

The additional check for non-empty OriginalText appropriately prevents the legacy suffix stripping logic from executing when ArchiveFileName is effectively empty. This refinement ensures that the transformation only applies when there's meaningful legacy configuration to handle.


454-454: LGTM: Proper cache invalidation.

Setting _fileArchiveHandler to null ensures the archive handler is recreated with the updated ArchiveSuffixFormat, consistent with other property setters in the class (lines 272, 293, 341, 359, 375).

@snakefoot snakefoot force-pushed the FIleTargetRemoveNoise branch from 9a5f807 to 6082187 Compare December 20, 2025 09:32
@sonarqubecloud
Copy link

@snakefoot snakefoot merged commit f206dc3 into NLog:dev Dec 21, 2025
5 of 6 checks passed
@snakefoot snakefoot added this to the 6.1.0 milestone Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement on existing feature file-archiving Issues with archiving with the file target file-target size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant