Trace.CorrelationManager 是否有等效的 .NET 标准?
Is there a .NET Standard equivalent for Trace.CorrelationManager?
在我的 .NET Framework 4.6.1 Web API 应用程序中,我使用 System.Diagnostics.Trace
class' CorrelationManager
属性,以及NLog,根据请求对日志消息进行分组。不幸的是,CorrelationManager
属性 似乎不再存在于 System.Diagnostics.Trace
上。我有两个问题:
- .NET Standard 中是否有替代概念?
- NLog 本身是否支持该替换?
看来 Microsoft.AspNetCore.Http.HttpContext.TraceIdentifier
就是我要找的。 NLog 目前不支持此功能。
NLog.Web 的 4.3.1 版本已经支持它。使用变量 ${aspnet-TraceIdentifier}
.
您也可以使用自定义逻辑,例如:
app.Use(next => {
return async context => {
context.TraceIdentifier = Guid.NewGuid().ToString();
await next(context);
};
});
在我的 .NET Framework 4.6.1 Web API 应用程序中,我使用 System.Diagnostics.Trace
class' CorrelationManager
属性,以及NLog,根据请求对日志消息进行分组。不幸的是,CorrelationManager
属性 似乎不再存在于 System.Diagnostics.Trace
上。我有两个问题:
- .NET Standard 中是否有替代概念?
- NLog 本身是否支持该替换?
看来 Microsoft.AspNetCore.Http.HttpContext.TraceIdentifier
就是我要找的。 NLog 目前不支持此功能。
NLog.Web 的 4.3.1 版本已经支持它。使用变量 ${aspnet-TraceIdentifier}
.
您也可以使用自定义逻辑,例如:
app.Use(next => {
return async context => {
context.TraceIdentifier = Guid.NewGuid().ToString();
await next(context);
};
});