Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
GelfLayout - Align with SplunkLayout
  • Loading branch information
snakefoot committed Jul 13, 2025
commit e7c42bb3a249c58f649a22a50b4d90c9ffe7e30b
8 changes: 4 additions & 4 deletions src/NLog.Targets.Network/Layouts/GelfLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ protected override void InitializeLayout()
{
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}"));
}
Comment on lines 174 to 181
Copy link
Copy Markdown

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.


// CompoundLayout includes optimization, so only doing precalculate/caching of relevant Layouts (instead of the entire GELF-message)
Expand Down
2 changes: 1 addition & 1 deletion tests/NLog.Targets.Network.Tests/GelfLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void CanRenderGelf()
+ "\"short_message\":\"{1}\","
+ "\"timestamp\":{2},"
+ "\"level\":{3},"
+ "\"_logLevel\":\"{4}\","
+ "\"_loglevel\":\"{4}\","
+ "\"_logger\":\"{5}\""
+ "}}",
HostName,
Expand Down