如何找出Application_End在Azure App Service上触发的原因

时间:2016-02-10 00:01:13

标签: c# asp.net asp.net-mvc azure azure-web-sites

我们在Azure上托管了一个MVC ASP.NET Web应用程序作为App Service。 一天3或4次我可以看到它重新启动。我正在foreach中将&$val记录在global.asax中,原因可归结为“配置更改”,根据文档显示应用程序配置已更改。

我问过我们的小团队,并没有人手动改变配置。搜索代码我没有看到我们以编程方式更改它的任何地方。 azure站点配置为始终打开。内存使用在发生时并未接近极限,但在更高的流量时间内似乎更常发生。

有没有办法获取特定文件的更改,以便我可以在$key中记录?或者通过其他方式获得更多细节?

1 个答案:

答案 0 :(得分:3)

Scott Guthrie has a blog post on how to get more information out of the Application Shut Down events using reflection. I would read his post in detail to find out more about issues.

The code snippet from Scott's page to pull more information out is the following. You could then log it with what ever tool you are using.

 HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime)
                                                  .InvokeMember("_theRuntime",
                                                                 BindingFlags.NonPublic
                                                                 | BindingFlags.Static
                                                                 | BindingFlags.GetField,
                                                                 null,
                                                                 null,
                                                                 null);

 if (runtime == null)
     return;

 string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage",
                                                                 BindingFlags.NonPublic
                                                                |BindingFlags.Instance
                                                                |BindingFlags.GetField,
                                                                         null,
                                                                         runtime,
                                                                         null);

 string shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack",
                                                                 BindingFlags.NonPublic
                                                                | BindingFlags.Instance
                                                                | BindingFlags.GetField,
                                                                       null,
                                                                       runtime,
                                                                       null);

It is mentioned in the comments that you may need certain permissions on the code to be able to perform the private reflection.

Good luck and I hope this helps you get closer to solving the issue.