Skip to content

LoggingRule - Update FinalMinLevel to match NLog.config#6118

Merged
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:FinalMinLevelRule
Mar 14, 2026
Merged

LoggingRule - Update FinalMinLevel to match NLog.config#6118
snakefoot merged 1 commit intoNLog:devfrom
snakefoot:FinalMinLevelRule

Conversation

@snakefoot
Copy link
Copy Markdown
Contributor

@snakefoot snakefoot commented Mar 14, 2026

When specifying FinalMinLevel in Nlog.config, then it also implicitly assigns MinLevel (unless explicitly assigned).

@snakefoot snakefoot added this to the 6.1.2 milestone Mar 14, 2026
@snakefoot snakefoot added the enhancement Improvement on existing feature label Mar 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8cc8b069-95c6-413a-9208-bdf509a74501

📥 Commits

Reviewing files that changed from the base of the PR and between e778708 and df3d2f2.

📒 Files selected for processing (2)
  • src/NLog/Config/LoggingRule.cs
  • tests/NLog.UnitTests/Config/ConfigApiTests.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/NLog/Config/LoggingRule.cs
  • tests/NLog.UnitTests/Config/ConfigApiTests.cs

Walkthrough

The FinalMinLevel setter in LoggingRule now assigns MinLevel when the rule's _logLevelFilter is Off and the new FinalMinLevel value is non-null, then calls SetFinalMinLevel(value); the _logLevelFilter update is unchanged.

Changes

Cohort / File(s) Summary
Logging Rule Configuration
src/NLog/Config/LoggingRule.cs
Updated FinalMinLevel setter: if _logLevelFilter == LoggingRuleLevelFilter.Off and value != null, set MinLevel = value before invoking SetFinalMinLevel(value); _logLevelFilter update remains the same.
Unit Tests
tests/NLog.UnitTests/Config/ConfigApiTests.cs
Added LogRuleFinalMinLevel_enables() unit test asserting that setting FinalMinLevel from Off populates Levels with Warn, Error, Fatal and updates MinLevel to Warn.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I twitched my nose at Final's call,

From Off to Warn I saved the fall,
Min and Final now hop in line,
Levels bloom Warn, Error, Fatal—fine!

🚥 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 accurately reflects the main change: updating FinalMinLevel behavior in LoggingRule to match NLog.config specifications.
Description check ✅ Passed The description clearly explains the change: FinalMinLevel now implicitly assigns MinLevel unless explicitly assigned, which directly relates to the code modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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
Copy Markdown

@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.

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

343-352: Test correctly validates new FinalMinLevel behavior.

The test appropriately mirrors LogRuleMinLevel_enables and validates that setting FinalMinLevel on a fresh rule in the Off state enables the expected levels and updates MinLevel.

Consider adding a complementary test verifying that FinalMinLevel does not update MinLevel when the rule already has levels enabled (i.e., when _logLevelFilter is not Off). This would ensure the conditional logic in the setter is fully exercised.

💡 Optional: Additional test for non-Off state
[Fact]
public void LogRuleFinalMinLevel_DoesNotChangeExistingMinLevel()
{
    var rule = new LoggingRule();
    rule.MinLevel = LogLevel.Debug; // Rule is no longer in Off state
    rule.FinalMinLevel = LogLevel.Warn;
    // MinLevel should remain Debug, not change to Warn
    Assert.Equal(LogLevel.Debug, rule.MinLevel);
    Assert.Equal(new[] { LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error, LogLevel.Fatal }, rule.Levels);
}

,

🤖 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 343 - 352, Add a
complementary unit test to exercise the conditional in the
LoggingRule.FinalMinLevel setter: create a test (e.g.,
LogRuleFinalMinLevel_DoesNotChangeExistingMinLevel) that constructs a
LoggingRule, sets rule.MinLevel = LogLevel.Debug (so _logLevelFilter is not
Off), then sets rule.FinalMinLevel = LogLevel.Warn and asserts that
rule.MinLevel remains LogLevel.Debug and rule.Levels contains the
debug-through-fatal levels; this verifies FinalMinLevel does not override an
existing MinLevel.
🤖 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 343-352: Add a complementary unit test to exercise the conditional
in the LoggingRule.FinalMinLevel setter: create a test (e.g.,
LogRuleFinalMinLevel_DoesNotChangeExistingMinLevel) that constructs a
LoggingRule, sets rule.MinLevel = LogLevel.Debug (so _logLevelFilter is not
Off), then sets rule.FinalMinLevel = LogLevel.Warn and asserts that
rule.MinLevel remains LogLevel.Debug and rule.Levels contains the
debug-through-fatal levels; this verifies FinalMinLevel does not override an
existing MinLevel.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8c18ed1c-7815-440b-968d-d4640121c2a6

📥 Commits

Reviewing files that changed from the base of the PR and between b6622a9 and e778708.

📒 Files selected for processing (2)
  • src/NLog/Config/LoggingRule.cs
  • tests/NLog.UnitTests/Config/ConfigApiTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/NLog/Config/LoggingRule.cs

@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

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