Visitar URL original
LoggingRule - Updating FinalMinLevel should also update MinLevel when same LogLevel by snakefoot · Pull Request #6149 · NLog/NLog · GitHub
Skip to content

LoggingRule - Updating FinalMinLevel should also update MinLevel when same LogLevel - #6149

Merged
snakefoot merged 1 commit into
NLog:devfrom
snakefoot:LoggingRuleFinalMinLevel
Apr 11, 2026
Merged

snakefoot merged 1 commit into
NLog:devfrom
snakefoot:LoggingRuleFinalMinLevel

Conversation

@snakefoot

@snakefoot snakefoot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

Only when LoggingRule has its own Targets, then it makes sense to have different values for FinalMinLevel and MinLevel.

@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

Walkthrough

Modified the FinalMinLevel setter in LoggingRule to synchronize MinLevel when either the log level filter is Off or when its FinalMinLevel equals the current MinLevel with no targets present. Test coverage expanded to validate the updated behavior across multiple scenarios.

Changes

Cohort / File(s) Summary
FinalMinLevel Synchronization Logic
src/NLog/Config/LoggingRule.cs, tests/NLog.UnitTests/Config/ConfigApiTests.cs
Expanded FinalMinLevel setter condition to sync MinLevel in additional cases; test assertions now comprehensively verify synchronization behavior, independence of property changes, and final state consistency.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A setter's logic grows more wise,
With broader conditions that harmonize,
When targets vanish and levels align,
MinLevel dances in rhythm—so fine!
Tests multiply to keep things tight,
Our logging rules now shimmer bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: updating FinalMinLevel to also update MinLevel under certain conditions.
Description check ✅ Passed The pull request description clearly explains the condition under which FinalMinLevel and MinLevel synchronization should occur - only when LoggingRule has its own Targets.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@snakefoot snakefoot added the enhancement Improvement on existing feature label Apr 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/NLog.UnitTests/Config/ConfigApiTests.cs (1)

349-365: Add one assertion path for the Targets.Count > 0 guard.

This test now covers the empty-target synchronization behavior well. Consider adding a small case where a target is present, then updating FinalMinLevel, and asserting MinLevel is not implicitly updated (to lock in Line 179’s Targets.Count == 0 contract).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/NLog.UnitTests/Config/ConfigApiTests.cs` around lines 349 - 365, Add a
new assertion path to cover the case when a target exists so FinalMinLevel
changes do not implicitly update MinLevel: create or reuse the existing "rule"
with at least one target (ensure rule.Targets.Count > 0), set rule.MinLevel to
some value, then change rule.FinalMinLevel and assert that rule.MinLevel remains
unchanged while rule.FinalMinLevel reflects the new value; reference the
existing usages of rule.MinLevel and rule.FinalMinLevel in the test to locate
where to insert this case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/NLog.UnitTests/Config/ConfigApiTests.cs`:
- Around line 349-365: Add a new assertion path to cover the case when a target
exists so FinalMinLevel changes do not implicitly update MinLevel: create or
reuse the existing "rule" with at least one target (ensure rule.Targets.Count >
0), set rule.MinLevel to some value, then change rule.FinalMinLevel and assert
that rule.MinLevel remains unchanged while rule.FinalMinLevel reflects the new
value; reference the existing usages of rule.MinLevel and rule.FinalMinLevel in
the test to locate where to insert this case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 84c0c072-5ece-4798-90d3-ac52f254cb0d

📥 Commits

Reviewing files that changed from the base of the PR and between 63c0484 and 19df781.

📒 Files selected for processing (2)
  • src/NLog/Config/LoggingRule.cs
  • tests/NLog.UnitTests/Config/ConfigApiTests.cs

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@snakefoot
snakefoot merged commit 560a436 into NLog:dev Apr 11, 2026
6 of 7 checks passed
@snakefoot snakefoot added this to the 6.1.3 milestone May 4, 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 size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant