【问题标题】:How to add a request identifier to OWIN requests using Serilog?如何使用 Serilog 向 OWIN 请求添加请求标识符?
【发布时间】:2017-09-19 08:07:39
【问题描述】:

我正在尝试与使用 SerilogWeb.Classic.WebApi 一样:

app.Use(async (owinContext, next) =>
{
    using (Serilog.Context.LogContext.PushProperty("HttpRequestId", Guid.NewGuid()))
    {
        await next();
    }
});

还有这个模板

{Timestamp:yyyy-MM-dd HH:mm:ss.ffffff zzz} [{Level:u3}] {HttpRequestId}: {SourceContext}: {Message} {Scope}{NewLine}{Exception}

但是HtpRequestId 在日志中总是空的:

2017-09-18 23:26:13.056013 +01:00 [WRN] : <SourceContext>: <message>

我做错了什么?

【问题讨论】:

    标签: asp.net-web-api owin serilog owin-middleware


    【解决方案1】:

    您是否已将Enrich.FromLogContext() 添加到您的 Serilog 配置中?在拾取环境上下文属性并将其添加到事件之前,需要选择加入。

    【讨论】:

    • 这就是我所缺少的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    相关资源
    最近更新 更多