【发布时间】:2014-06-16 15:09:02
【问题描述】:
我想log Thread-ID 是为了跟踪请求并使日志文件可读。
所以,我最初的尝试是这样logging in Global.asax:
protected void Application_BeginRequest()
{
log4net.ILog writer = log4net.LogManager.GetLogger(this.GetType());
writer.InfoFormat("Gotta service a request. Id = {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
}
protected void Application_EndRequest()
{
log4net.ILog writer = log4net.LogManager.GetLogger(this.GetType());
writer.InfoFormat("Completed servicing a request. Id = {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
}
但是当我看到日志文件时,很奇怪。
2014-06-16 20:27:06,018 - Gotta service a request. Id = 286 --> From Application_BeginRequest()
2014-06-16 20:27:06,042 - Servicing Request Thread-Id = 286 --> this message comes from controller
2014-06-16 20:27:06,043 - Thread-Id = 286 --> this message comes from controller
2014-06-16 20:27:06,237 - Completed servicing a request. Id = 287 --> From Application_EndRequest()
在Application_Start 中,Thread-Id 是286,但是当它返回到Application_EndRequest 时,Thread-Id changed to 287。
服务整个HTTP request的不是一个线程吗?
有什么想法吗?
【问题讨论】:
-
可能是在使用异步操作
-
@Jonesy:好的,那么有什么想法可以跟踪请求吗?
标签: c# asp.net .net asp.net-mvc asp.net-web-api