Labels

Tuesday, February 3, 2009

Determine What made Web-Application Shutdown

Hi,

 

Here in this post I’ll summarize the details of this approach.

 

There are multiple reasons of auto shutdown of the Web Application.

 

·          Web.config file change, a

·          Global.asax change

·          App_code directory change

·          A directory delete change

·          Max-num-compilations reached quota.

·          \bin directory change etc.

 

Now to identify which of the above made the application shutdown, use the below snippet.

 

 

 

void Application_End(object sender, EventArgs e)

    {

        //  Code that runs on application shutdown

 

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

              

        if (!EventLog.SourceExists(".NET Runtime"))

        {

            EventLog.CreateEventSource(".NET Runtime", "Application");

        }

 

        EventLog log = new EventLog();

 

        log.Source = ".NET Runtime";

        log.WriteEntry(String.Format("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}",shutDownMessage,shutDownStack), EventLogEntryType.Error);

    }

 

 

 

Now run the application and try to make changes in two files one by one respectively – Web.config and File under App_Code directory.

When the changes are made respectively, these will make the application shut down. This causes makes below logging in the Event Log under ‘Application’ Event Viewer.

 

 

 

 

_shutDownMessage=CONFIG change

HostingEnvironment initiated shutdown

CONFIG change

HostingEnvironment caused shutdown

 

_shutDownStack=   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)

   at System.Environment.get_StackTrace()

   at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()

   at System.Web.Hosting.HostingEnvironment.InitiateShutdown()

   at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)

   at System.Web.Configuration.HttpConfigurationSystem.OnConfigurationChanged(Object sender, InternalConfigEventArgs e)

   at System.Configuration.Internal.InternalConfigRoot.OnConfigChanged(InternalConfigEventArgs e)

   at System.Configuration.BaseConfigurationRecord.OnStreamChanged(String streamname)

   at System.Web.Configuration.WebConfigurationHostFileChange.OnFileChanged(Object sender, FileChangeEvent e)

   at System.Web.DirectoryMonitor.FireNotifications()

   at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)

   at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state).

 

 

 

_shutDownMessage=Change Notification for critical directories.

App_Code dir change or directory rename

HostingEnvironment initiated shutdown

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

Change Notification for critical directories.

App_Code dir change or directory rename

HostingEnvironment caused shutdown

 

_shutDownStack=   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)

   at System.Environment.get_StackTrace()

   at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()

   at System.Web.Hosting.HostingEnvironment.InitiateShutdown()

   at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)

   at System.Web.HttpRuntime.OnCriticalDirectoryChange(Object sender, FileChangeEvent e)

   at System.Web.FileChangesMonitor.OnCriticaldirChange(Object sender, FileChangeEvent e)

   at System.Web.DirectoryMonitor.FireNotifications()

   at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)

   at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state).

 

 

 

 

Hope this helps.

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

No comments:

Post a Comment