问题
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