How to unique identify each request in a ASP.NET Core 2 application (for logging)

前端 未结 3 1162
星月不相逢
星月不相逢 2021-01-01 14:39

In a ASP.NET Core 2 application, I need a unique identifier (e.g. Guid) for each request so I can include that id in each log and understand the sequence of logs of each req

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 15:01

    You may use System.Diagnostics.Activity class (source). From Activity User Guide

    Activity.Id serves as hierarchical Request-Id in terms of HTTP Correlation Protocol

    This is used for example by Microsoft/ApplicationInsights-aspnetcore for app monitoring.

提交回复
热议问题