gpt4 book ai didi

c# - 如何找出 Application_End 在 Azure 应用服务上触发的原因

转载 作者:行者123 更新时间:2023-11-30 20:38:17 27 4
gpt4 key购买 nike

我们有一个 MVC ASP.NET Web 应用程序作为应用服务托管在 Azure 上。每天有 3 到 4 次我可以看到它重新启动。我正在 global.asax 中的 Application_End() 中记录 System.Web.HostingEnvrionment.ShutdownReason ,原因返回为“配置更改”,根据文档,这意味着该应用程序配置已更改。

我询问过我们的小团队,没有人手动更改过配置。仔细检查代码,我没有看到任何我们以编程方式更改它的地方。 azure 站点配置为始终开启。发生这种情况时,内存使用并未接近极限,尽管在流量较高的时候,这种情况似乎更频繁地发生。

有没有办法获取特定文件的更改,以便我可以将其记录在 Application_End() 中?或者还有其他方法可以获取更多详细信息吗?

最佳答案

Scott Guthrie 有一篇关于如何获取更多 information out of the Application Shut Down events 的博客文章使用反射。我会详细阅读他的帖子以了解有关问题的更多信息。

来自 Scott 页面的代码片段用于提取更多信息,如下所示。然后,您可以使用您正在使用的任何工具来记录它。

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

评论中提到,您可能需要代码的某些权限才能执行私有(private)反射。

祝你好运,我希望这可以帮助您更接近解决问题。

关于c# - 如何找出 Application_End 在 Azure 应用服务上触发的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35304556/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com