From 25cfe0193ce44dc71ab4a3a1bbb088adacfbbb9d Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 22 Sep 2015 12:19:14 +0200 Subject: [PATCH] adds detailed shutdown info to logs by default --- src/Umbraco.Core/UmbracoApplicationBase.cs | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index 5b9c8903c6..6aadbd269a 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Web; using System.Web.Hosting; using log4net; @@ -180,7 +182,47 @@ namespace Umbraco.Core { if (SystemUtilities.GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted) { - Logger.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); + //Try to log the detailed shutdown message (typical asp.net hack: http://weblogs.asp.net/scottgu/433194) + try + { + var runtime = (HttpRuntime)typeof(HttpRuntime).InvokeMember("_theRuntime", + BindingFlags.NonPublic + | BindingFlags.Static + | BindingFlags.GetField, + null, + null, + null); + if (runtime == null) + return; + + var shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage", + BindingFlags.NonPublic + | BindingFlags.Instance + | BindingFlags.GetField, + null, + runtime, + null); + + var shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack", + BindingFlags.NonPublic + | BindingFlags.Instance + | BindingFlags.GetField, + null, + runtime, + null); + + var shutdownMsg = string.Format("{0}\r\n\r\n_shutDownMessage={1}\r\n\r\n_shutDownStack={2}", + HostingEnvironment.ShutdownReason, + shutDownMessage, + shutDownStack); + + Logger.Info("Application shutdown. Details: " + shutdownMsg); + } + catch (Exception) + { + //if for some reason that fails, then log the normal output + Logger.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); + } } OnApplicationEnd(sender, e);