Skip to content

Commit 5c69d5f

Browse files
committed
fix: 实现 扩展属性内置Scope处理
1 parent 76ec59c commit 5c69d5f

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

framework/src/Bing.Logging.Sinks.Exceptionless/Serilog/Sinks/Exceptionless/ExceptionlessSink.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Bing;
55
using Bing.Logging.ExtraSupports;
66
using Bing.Logging.Sinks.Exceptionless.Internals;
7+
using Bing.Text;
78
using Exceptionless;
89
using Exceptionless.Dependency;
910
using Exceptionless.Logging;
@@ -148,7 +149,15 @@ public void Emit(LogEvent logEvent)
148149
}
149150
break;
150151
default:
151-
builder.SetProperty(property.Key, property.Value.FlattenProperties());
152+
{
153+
// 特殊处理扩展属性
154+
if (property.Key.StartsWith(ContextDataTypes.ExtraProperty))
155+
{
156+
builder.SetProperty(property.Key.TrimPhraseStart(ContextDataTypes.ExtraProperty), property.Value.FlattenProperties());
157+
break;
158+
}
159+
builder.SetProperty(property.Key, property.Value.FlattenProperties());
160+
}
152161
break;
153162
}
154163
}

framework/src/Bing.Logging/Bing/Logging/Core/LogEventContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public LogEventContext SetExtraProperty(string name, object value)
9595
{
9696
if (string.IsNullOrWhiteSpace(name))
9797
return this;
98-
_extraProperties.AddOrUpdateItem($"{ContextDataTypes.ExtraProperty}_{name}", value, false);
98+
_extraProperties.AddOrUpdateItem($"{ContextDataTypes.ExtraProperty}{name}", value, false);
9999
return this;
100100
}
101101

framework/src/Bing.Logging/Bing/Logging/ExtraSupports/ContextDataTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ContextDataTypes
88
/// <summary>
99
/// 扩展属性
1010
/// </summary>
11-
public const string ExtraProperty = "__BING_EXTRA_PROPERTY";
11+
public const string ExtraProperty = "__BING_EXTRA_PROPERTY_";
1212

1313
/// <summary>
1414
/// 扩展属性

samples/Bing.Samples.Hangfire/Jobs/DebugLogJob.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Bing.Logging;
77
using Bing.Logs;
88
using Bing.Logs.Abstractions;
9+
using Bing.Utils.Json;
910
using Exceptionless;
1011
using Microsoft.Extensions.Logging;
1112
using el = global::Exceptionless;
@@ -82,6 +83,8 @@ public void WriteLog()
8283
}))
8384
{
8485
CurrentLog.ExtraProperty("testA7777", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.sss"))
86+
.ExtraProperty("Req", new { A = 1, B = "2", C = new { C1 = 1, C2 = id } })
87+
.ExtraProperty("ReqJson", JsonHelper.ToJson(new { A = 1, B = "2", C = new { C1 = 1, C2 = id } }))
8588
.Message($"测试日志信息--双重设置--BeginScope {id}")
8689
.Tags(id)
8790
.LogInformation();

samples/Bing.Samples.Hangfire/Modules/LogModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public override IServiceCollection AddServices(IServiceCollection services)
4141
// 同时输出2种方式的日志,可能存在重复 需要陆续兼容
4242
Logs.Exceptionless.Extensions.AddExceptionless(services, o =>
4343
{
44-
o.ApiKey = "N8HOaOLndl0hF7ZhOfiwJ9HmOi6kPwjKEKWLCMzE";
45-
o.ServerUrl = "http://10.186.132.40:5100";
44+
o.ApiKey = "2R8FksPOpJikquJ2SLUfZMNES6d6dIsBsFYWTJR7";
45+
o.ServerUrl = "http://10.186.135.27:5100";
4646
});
4747
services.AddBingLogging(x => { });
4848
services.AddSingleton<ILogContextAccessor, LogContextAccessor>();

0 commit comments

Comments
 (0)