Skip to content

Commit e51ebf2

Browse files
committed
fix: 修复Log存在重复属性时,忽略处理
1 parent 3b6779e commit e51ebf2

File tree

2 files changed

+8
-4
lines changed
  • framework

2 files changed

+8
-4
lines changed

framework/src/Bing.Logging/Bing/Logging/Log.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ protected virtual void ConvertStateToContent()
269269
{
270270
if (item.Value.SafeString().IsEmpty())
271271
continue;
272-
LogProperties.Add(item);
272+
if (LogProperties.ContainsKey(item.Key))
273+
LogProperties[item.Key] = item.Value;
274+
else
275+
LogProperties.Add(item.Key, item.Value);
273276
}
274277
}
275278

framework/tests/Bing.Logging.Serilog.Tests/LogTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ public void Test_LogTrace_Message_9()
113113
_log.EventId(119)
114114
.Message("Test_LogTrace_Message_9_{id}", $"id_{Id.NewString()}")
115115
.State(new Product { Code = "a", Name = "b", Price = 123 })
116-
.Property("Age","18")
117-
.Property("Description","hello")
116+
.Property("Code", "a")
117+
.Property("Age", "18")
118+
.Property("Description", "hello")
118119
.LogTrace();
119120
}
120121

@@ -142,4 +143,4 @@ public void Test_LogTrace_Property_2()
142143
.State(new Product { Code = "a", Name = "b", Price = 123 })
143144
.LogTrace();
144145
}
145-
}
146+
}

0 commit comments

Comments
 (0)