如何检查IIS或ASP.NET辅助进程自动重新启动我的网站?

问题描述:

我想知道我是否可以跟踪这一点,因为如果经常发生这种情况,我想知道它的根本原因。有没有时间戳记录可我在IIS站点的重新启动,我如何追踪这个编程?

I want to know if I can track this, because if this happens frequently I want to know root cause of it. Is there any time stamp logging available for restarting of my site in IIS, How can I track this programmatically?

感谢所有。

您可以登录原因Global.asax中Application_End应用程序重新启动:

You could log reason for application restart in Global.asax Application_End :

protected void Application_End(object sender, EventArgs e)
{
  HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);

  string shutDownMessage = "";

  if (runtime != null)
  {
    shutDownMessage = Environment.NewLine + "Shutdown: " +
                      (string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) + 
                      Environment.NewLine + "Stack: " + Environment.NewLine +
                      (string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
  }
}