Skip to content

Conversation

@snakefoot
Copy link
Contributor

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

Walkthrough

The changes update the naming convention of default GELF fields in the layout initialization to use lowercase and underscores, and adjust related test expectations accordingly. No public APIs or exported entity signatures are modified; all changes are internal to layout initialization logic and test string templates.

Changes

Files Change Summary
src/NLog.Targets.Network/Layouts/GelfLayout.cs Renamed default GELF fields to use lowercase and underscores; removed IncludeEmptyValue = false flag.
tests/NLog.Targets.Network.Tests/GelfLayoutTests.cs Updated test expectation to match new GELF field naming convention.

Poem

In fields of logs, we hop and tweak,
From camel humps to underscores sleek.
Lowercase now, our tails held high,
The GELF fields changed, oh my oh my!
With tests aligned, we leap ahead,
A tidy warren for logs to tread.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Nitpick comments (1)
tests/NLog.Targets.Network.Tests/GelfLayoutTests.cs (1)

85-85: Test correctly updated but consider expanding coverage for other default fields.

The test correctly reflects the field name change from "_logLevel" to "_loglevel". However, the test doesn't verify the other renamed default fields ("_exception_type", "_exception_msg", "_exception") that were also changed in the implementation.

Consider adding test coverage for exception-related fields to ensure they render correctly with the new naming convention:

[Fact]
public void CanRenderGelfWithException()
{
    var gelfLayout = new GelfLayout();
    
    var logEvent = new LogEventInfo
    {
        LoggerName = "TestLogger",
        Level = LogLevel.Error,
        Message = "Error occurred",
        Exception = new InvalidOperationException("Test exception"),
        TimeStamp = DateTime.Now,
    };
    
    var result = gelfLayout.Render(logEvent);
    
    // Verify new exception field names are present
    Assert.Contains("\"_exception_type\":", result);
    Assert.Contains("\"_exception_msg\":", result);
    Assert.Contains("\"_exception\":", result);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e360886 and e7c42bb.

📒 Files selected for processing (2)
  • src/NLog.Targets.Network/Layouts/GelfLayout.cs (1 hunks)
  • tests/NLog.Targets.Network.Tests/GelfLayoutTests.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/NLog.Targets.Network/Layouts/GelfLayout.cs (1)
src/NLog/Targets/TargetPropertyWithContext.cs (2)
  • TargetPropertyWithContext (51-51)
  • TargetPropertyWithContext (58-62)

Comment on lines 174 to 181
if (GelfFields.Count == 0)
{
GelfFields.Add(new TargetPropertyWithContext("_logLevel", "${level}"));
GelfFields.Add(new TargetPropertyWithContext("_loglevel", "${level}"));
GelfFields.Add(new TargetPropertyWithContext("_logger", "${logger}"));
GelfFields.Add(new TargetPropertyWithContext("_exceptionType", "${exception:Format=Type}") { IncludeEmptyValue = false });
GelfFields.Add(new TargetPropertyWithContext("_exceptionMessage", "${exception:Format=Message}") { IncludeEmptyValue = false });
GelfFields.Add(new TargetPropertyWithContext("_stackTrace", "${exception:Format=ToString}") { IncludeEmptyValue = false });
GelfFields.Add(new TargetPropertyWithContext("_exception_type", "${exception:Format=Type}"));
GelfFields.Add(new TargetPropertyWithContext("_exception_msg", "${exception:Format=Message}"));
GelfFields.Add(new TargetPropertyWithContext("_exception", "${exception:Format=ToString}"));
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Breaking change: Verify backward compatibility impact and alignment with standards.

The field name changes from camelCase to lowercase with underscores represent a breaking change for existing GELF consumers. Additionally, line 180 changes both the field name (from "_stackTrace" to "_exception") and the format (from individual exception components to ToString format).

Ensure that:

  1. This aligns with the intended GELF standard or SplunkLayout conventions
  2. Existing deployments can handle this change gracefully
  3. Consider providing a migration guide for users

🏁 Script executed:

#!/bin/bash
# Search for any documentation about GELF field naming standards
rg -i "gelf.*field.*standard|field.*naming.*convention" --type md
rg -i "splunk.*layout.*field" --type cs

Length of output: 109


🏁 Script executed:

#!/bin/bash
# Check for any remaining references to the old field names in code/tests
rg -n '"_logLevel"' -t cs
rg -n '"_exceptionType"' -t cs
rg -n '"_exceptionMessage"' -t cs
rg -n '"_stackTrace"' -t cs

# Inspect XML doc and surrounding code for default field description
sed -n '150,230p' src/NLog.Targets.Network/Layouts/GelfLayout.cs

Length of output: 3848


Breaking Change: Default GELF Field Names and Exception Format Updated

The InitializeLayout defaults now use lowercase-underscore field names and switch from a separate _stackTrace field to a combined _exception (ToString) value. This will break existing GELF consumers relying on the old camelCase names and individual exception components.

Please address the following before merging:

• Confirm these names and formats align with your intended GELF conventions (or SplunkLayout standards).
• Update any user documentation or examples to reflect the new defaults.
• Provide a clear migration guide or configuration option for users who need the previous field names (_logLevel, _exceptionType, _exceptionMessage, _stackTrace) and formats.

Affected location:

  • src/NLog.Targets.Network/Layouts/GelfLayout.cs lines 174–181
🤖 Prompt for AI Agents
In src/NLog.Targets.Network/Layouts/GelfLayout.cs lines 174 to 181, the default
GELF field names have changed to lowercase with underscores and the exception
fields have been consolidated into a single _exception field using ToString
format. Review and confirm these new field names and formats match your GELF or
SplunkLayout conventions. Update all related user documentation and examples to
reflect these changes. Additionally, implement a migration guide or provide a
configuration option that allows users to revert to the previous camelCase field
names and separate exception fields (_logLevel, _exceptionType,
_exceptionMessage, _stackTrace) if needed.

@sonarqubecloud
Copy link

@snakefoot snakefoot merged commit 308cf2d into NLog:dev Jul 13, 2025
6 checks passed
@snakefoot snakefoot added this to the 6.0.2 milestone Jul 18, 2025
This was referenced Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant