在Sentry.serilog中添加自定义动态标签
我正在尝试通过corseLationId属性来丰富日志,我有这样的中间件,在这里,我在其中生成并将属性推向serilog logcontext
public class LogContextMiddleware : IMiddleware
{
private readonly ICorrelationIdFactory _correlationIdFactory;
public LogContextMiddleware(ICorrelationIdFactory correlationIdFactory)
{
_correlationIdFactory = correlationIdFactory;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var correlationId = _correlationIdFactory.Create();
using(LogContext.PushProperty("CorrelationId", correlationId))
{
await next(context);
}
}
}
具有Sentry.serilog设置为这样:
.WriteTo.Sentry(o =>
{
o.MinimumBreadcrumbLevel = LogEventLevel.Information;
o.MinimumEventLevel = LogEventLevel.Error;
o.Dsn = "<dsn url>";
o.AttachStacktrace = true;
o.TextFormatter = new MessageTemplateTextFormatter("[{CorrelationId}] {Message}", null);
});
但是我在任何标签中都没有看到CorralationId,在sentry UI中的标签部分中,或在消息格式化的文本输出中。只是在这里空[]。
信息
[]无法创建“ “ 因为'“令牌为空”'
我错过了配置的什么?提前致谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定它是否是正确的解决方案,但也许会对您有所帮助。
I am not sure if it is correct solution, but maybe it will help for you.
https://github.com/getsentry/sentry-dotnet/blob/main/samples/Sentry.Samples.AspNetCore.Serilog/Program.cs#L53