如何访问 ASP.NET/IIS ContextId
我在事件日志中多次看到给定 ASP.NET 请求的“ContextId”。我最近开始研究 ASP.NET 推出的 ETW 事件,并希望在我自己触发的事件中重用此 ContextID。
我该怎么做?
System.Threading.Thread.CurrentContext 似乎没有它。始终是 0。
I've seen way too many times in my event logs this "ContextId" for a given ASP.NET request. I've recently started looking into ETW events that are pushed out by ASP.NET, and want to re-use this ContextID in my own events that I fire.
How can I do this?
System.Threading.Thread.CurrentContext doesn't seem to have it. It's always 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个记录很少的功能,但是你可以得到它。
它位于 HttpWorkerRequest RequestTraceIdentifier 属性上。
http://msdn.microsoft.com/en-us /library/system.web.httpworkerrequest.requesttraceidentifier.aspx
This is a poorly documented feature, but yes you can get it.
It sits on the HttpWorkerRequest RequestTraceIdentifier property.
http://msdn.microsoft.com/en-us/library/system.web.httpworkerrequest.requesttraceidentifier.aspx
您可以从 HttpWorkerRequest.RequestTraceIdentifier 属性获取它。请注意,显然您需要启用 IIS ETW(Windows 事件跟踪)功能,否则此属性将为
Guid.Empty
。以下是如何从HttpContext
获取它:参考:https://github.com/serilog/serilog/commit/b289dbcde3e0f7366d90daf66e00c94f4cc58de3#diff-4934d624fc1d467b08411d520972e840R48
You can get it from the
HttpWorkerRequest.RequestTraceIdentifier
property. Note that obviously you need to have the IIS ETW (Event Tracing for Windows) feature enabled or this property will beGuid.Empty
. The following is how to get it fromHttpContext
:Reference: https://github.com/serilog/serilog/commit/b289dbcde3e0f7366d90daf66e00c94f4cc58de3#diff-4934d624fc1d467b08411d520972e840R48