Пример #1
0
        /// <summary>
        /// Handles the End event of the application
        /// </summary>
        protected virtual void Application_End()
        {
            HttpRuntime runtime = (HttpRuntime)typeof(HttpRuntime).InvokeMember(
                "_theRuntime",
                BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField,
                null,
                null,
                null);

            if (runtime.IsNull())
            {
                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);
        }