1

在我部署在 Windows Azure 上的 ASP.NET 应用程序中,我想记录尽可能多的有用数据。有Application_End()办法:

protected void Application_End(object sender, EventArgs e)
{
}

sender这是与beingSystem.Web.HttpApplicationFactoryebeing just一起调用的System.EventArgs。有了这些参数,我所能做的就是记录它们的类型,这不是很有用。

我可以从这些参数中获得任何有用的数据吗?是否存在Application_End()使用具有其他更有用的实际类型的参数调用的情况?

4

1 回答 1

1

IIS,class HttpRuntime包括在内,可以下载源代码。仔细分析表明,事件参数确实总是相同的,没有传达任何有用的信息。事件的调用堆栈也是无用的 - 它总是

my Application_End(Object sender, EventArgs e)
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Web.HttpApplication.InvokeMethodWithAssert(MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs)
at System.Web.HttpApplication.ProcessSpecialRequest(HttpContext context, MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs, HttpSessionState session)
at System.Web.HttpApplicationFactory.Dispose()
at System.Web.HttpRuntime.Dispose()
at System.Web.HttpRuntime.ReleaseResourcesAndUnloadAppDomain(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

但是......System.Web.Hosting.HostingEnvironment.ShutdownReason可以从内部检索,并且在启动应用程序关闭时Application_End()设置。HttpRuntime

所以“有趣的数据”是System.Web.Hosting.HostingEnvironment.ShutdownReason

另请参阅这个密切相关的问题

于 2013-02-14T06:50:02.053 回答