How to discover the reason of ASP.NET application restart
<p>Is there a way to monitor (log) the reason for restarting of an ASP.NET application? </p>

<p>We now having problem with rather complex site. It's restarting during file upload. Not on every file, but on every 5th-10th for sure. We use custom VirtualPathProvider, so this could be a reason. We also have a background worker threads, and this also could be a reason. It would be great to just know the reason. </p>

<p>Problem occurs on XP (IIS 5.1) and Windows Server 2003 (IIS 6).</p>

<p><strong>Resolution:</strong></p>

<p>Thanks guys, we've managed to catch it. It is caused by max recompilations reached. Most likely the problem is in our VirtualPathProvider, but this is completely different question.</p>

<p>Summary of approaches:</p>

<ol>
<li>Hack in ScottGu's blog works perfect.</li>
<li>Monitoring via machine.config is also great, but I prefer to log it into our log.</li>
<li>As it turned out, simplest solution is to check <strong>HostingEnvironment.ShutdownReason</strong> property in my <strong>Application_End</strong> method.</li>
</ol>
