This might be useful to anyone that's experiencing unexpected application restarts. Add the code below to the site's
Global.asax file and whenever the site shuts down or restarts the reason will be logged in the nopCommerce log. It also adds an entry to windows event log so if the site is stuck in a restart loop and you can't get to the nop log page you possibly still see what's causing it.
It's based on code in this Scott Gu blog post, just with the nop logging added:
http://weblogs.asp.net/scottgu/433194Add these usings:
using Nop.Core.Domain.Logging;
using System.Diagnostics;
using System.Reflection;
Add the Application_End() event:
protected void Application_End()
{
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);
//log
var logger = EngineContext.Current.Resolve<ILogger>();
logger.InsertLog(LogLevel.Information,
"Application end",
String.Format("_shutDownMessage={0}\r\n\r\n_shutDownStack={1}",
shutDownMessage,
shutDownStack),
null);
}