|
1 | | -using Bing.Extensions; |
| 1 | +using System.Collections.Concurrent; |
| 2 | +using Bing.Collections; |
| 3 | +using Bing.Extensions; |
2 | 4 | using Bing.Helpers; |
3 | 5 | using Bing.Logging.Core; |
4 | 6 | using Bing.Text; |
@@ -30,7 +32,7 @@ public Log(ILoggerWrapper logger, ILogContextAccessor logContextAccessor = null) |
30 | 32 | { |
31 | 33 | Logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
32 | 34 | LogContext = logContextAccessor?.Context; |
33 | | - LogProperties = new Dictionary<string, object>(); |
| 35 | + LogProperties = new ConcurrentDictionary<string, object>(); |
34 | 36 | LogMessage = new StringBuilder(); |
35 | 37 | LogMessageArgs = new List<object>(); |
36 | 38 | CurrentDescriptor = new LogEventDescriptor(); |
@@ -77,7 +79,7 @@ public Log(ILoggerWrapper logger, ILogContextAccessor logContextAccessor = null) |
77 | 79 | /// <summary> |
78 | 80 | /// 日志内容 |
79 | 81 | /// </summary> |
80 | | - protected IDictionary<string, object> LogProperties { get; set; } |
| 82 | + protected ConcurrentDictionary<string, object> LogProperties { get; set; } |
81 | 83 |
|
82 | 84 | /// <summary> |
83 | 85 | /// 日志状态 |
@@ -130,7 +132,7 @@ public virtual ILog Property(string propertyName, string propertyValue) |
130 | 132 | LogProperties[propertyName] += propertyValue; |
131 | 133 | return this; |
132 | 134 | } |
133 | | - LogProperties.Add(propertyName, propertyValue); |
| 135 | + LogProperties.TryAdd(propertyName, propertyValue); |
134 | 136 | return this; |
135 | 137 | } |
136 | 138 |
|
@@ -267,7 +269,7 @@ protected virtual void ConvertStateToContent() |
267 | 269 | { |
268 | 270 | if (item.Value.SafeString().IsEmpty()) |
269 | 271 | continue; |
270 | | - LogProperties.Add(item); |
| 272 | + LogProperties.TryAdd(item.Key,item.Value); |
271 | 273 | } |
272 | 274 | } |
273 | 275 |
|
@@ -386,7 +388,7 @@ protected virtual void Clear() |
386 | 388 | LogEventId = 0; |
387 | 389 | LogException = null; |
388 | 390 | LogState = null; |
389 | | - LogProperties = new Dictionary<string, object>(); |
| 391 | + LogProperties = new ConcurrentDictionary<string, object>(); |
390 | 392 | LogMessage.Clear(); |
391 | 393 | LogMessageArgs.Clear(); |
392 | 394 | CurrentDescriptor = new LogEventDescriptor(); |
|
0 commit comments