how to check if IIS or ASP.NET worker process has restarted my website automatically?

我与影子孤独终老i 提交于 2019-12-12 02:32:16

问题


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?

Thanks to all.


回答1:


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);
  }
}



回答2:


on Global.asax the

void Application_Start(object sender, EventArgs e) 

and the

void Application_End(object sender, EventArgs e) 

are called when the application starts and ends. You can use them to log it. Now to know why your pool is restarting you can simple check the settings of your pool, there are many reasons that you may have setup, maybe you have set a time limit, maybe a memory limit, maybe other setup... you can check them and change them.



来源:https://stackoverflow.com/questions/10620177/how-to-check-if-iis-or-asp-net-worker-process-has-restarted-my-website-automatic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!