Skip to content

Commit f302dd2

Browse files
Fix log property name for CorrelationId and ClientHeader enricher.
1 parent f022182 commit f302dd2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Serilog.Enrichers.ClientInfo/Enrichers/ClientHeaderEnricher.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Serilog.Enrichers;
1515
public class ClientHeaderEnricher : ILogEventEnricher
1616
{
1717
private readonly string _clientHeaderItemKey;
18+
private readonly string _propertyName;
1819
private readonly string _headerKey;
1920
private readonly IHttpContextAccessor _contextAccessor;
2021

@@ -26,6 +27,7 @@ public ClientHeaderEnricher(string headerKey)
2627
internal ClientHeaderEnricher(string headerKey, IHttpContextAccessor contextAccessor)
2728
{
2829
_headerKey = headerKey;
30+
_propertyName = headerKey.Replace("-", "");
2931
_clientHeaderItemKey = $"Serilog_{headerKey}";
3032
_contextAccessor = contextAccessor;
3133
}
@@ -50,7 +52,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
5052
var headerValue = httpContext.Request.Headers[_headerKey].ToString();
5153
headerValue = string.IsNullOrWhiteSpace(headerValue) ? null : headerValue;
5254

53-
var logProperty = new LogEventProperty(_headerKey, new ScalarValue(headerValue));
55+
var logProperty = new LogEventProperty(_propertyName, new ScalarValue(headerValue));
5456
httpContext.Items.Add(_clientHeaderItemKey, logProperty);
5557

5658
logEvent.AddPropertyIfAbsent(logProperty);

src/Serilog.Enrichers.ClientInfo/Enrichers/CorrelationIdEnricher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Serilog.Enrichers;
1616
public class CorrelationIdEnricher : ILogEventEnricher
1717
{
1818
private const string CorrelationIdItemKey = "Serilog_CorrelationId";
19+
private const string PropertyName = "CorrelationId";
1920
private readonly string _headerKey;
2021
private readonly bool _addValueIfHeaderAbsence;
2122
private readonly IHttpContextAccessor _contextAccessor;
@@ -51,7 +52,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
5152
? header
5253
: (_addValueIfHeaderAbsence ? Guid.NewGuid().ToString() : null);
5354

54-
var correlationIdProperty = new LogEventProperty(_headerKey, new ScalarValue(correlationId));
55+
var correlationIdProperty = new LogEventProperty(PropertyName, new ScalarValue(correlationId));
5556
logEvent.AddOrUpdateProperty(correlationIdProperty);
5657

5758
httpContext.Items.Add(CorrelationIdItemKey, correlationIdProperty);

0 commit comments

Comments
 (0)