Skip to content

Commit 449b11e

Browse files
committed
Exclude "{OriginalFormat}" when provided through enrichment
1 parent b33c73e commit 449b11e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Serilog.Framework.Logging/SerilogLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Log(LogLevel logLevel, int eventId, object state, Exception exceptio
6464
{
6565
foreach (var property in structure.GetValues())
6666
{
67-
if (property.Key == "{OriginalFormat}" && property.Value is string)
67+
if (property.Key == SerilogLoggerProvider.OriginalFormatPropertyName && property.Value is string)
6868
{
6969
messageTemplate = (string)property.Value;
7070
}

src/Serilog.Framework.Logging/SerilogLoggerProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Serilog.Framework.Logging
1717
{
1818
public class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher
1919
{
20+
public const string OriginalFormatPropertyName = "{OriginalFormat}";
21+
2022
// May be null; if it is, Log.Logger will be lazily used
2123
readonly ILogger _logger;
2224

@@ -45,6 +47,9 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4547
{
4648
foreach (var keyValue in stateStructure.GetValues())
4749
{
50+
if (keyValue.Key == OriginalFormatPropertyName && keyValue.Value is string)
51+
continue;
52+
4853
var property = propertyFactory.CreateProperty(keyValue.Key, keyValue.Value);
4954
logEvent.AddPropertyIfAbsent(property);
5055
}

0 commit comments

Comments
 (0)