Is there a way to monitor (log) the reason for restarting of an ASP.NET application?
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.
Problem occurs on XP (IIS 5.1) and Windows Server 2003 (IIS 6).
Resolution:
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.
Summary of approaches:
- Hack in ScottGu’s blog works perfect.
- Monitoring via machine.config is also great, but I prefer to log it into our log.
- As it turned out, simplest solution is to check HostingEnvironment.ShutdownReason property in my Application_End method.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Have you looked at the logging suggestions from “Logging ASP.NET Application Shutdown Events “? That would be my suggestion for a way to get more information about what is happening.
Method 2
Adding or removing folders inside the applicaton folder will cause the app pool to recycle (the most likely reason in your case), along with many other things. Here’s an interesting article:
on the same site is some good hints on how to monitor the restarts which is what you were actually asking. The choices are web.config and EventViewer or Performance Monitor.
Method 3
Tess Ferrandez, ASP.NET Escalation Engineer has a good blog with all sorts of tips and tricks for debuging ASP.NET applications.
The posts you’re particularly interested in are:
- ASP.NET Case Study: Lost session variables and appdomain recycles
- Troubleshooting appdomain restarts and other issues with ETW tracing
She takes you through the step involved in working out what the problem is, and how to resolve it.
Another thing to watch out for is anti-virus software scanning files under the root of the site – this could change the modified date of the file, and cause the app to recycle.
Method 4
Take a look at this article from the Microsoft patterns & practices developer center:
Production Debugging for .NET Framework Applications
Also see this blog entry by Jeff Atwood:
Debugging ASPNET_WP in Production
Method 5
As others said check HostingEnvironment.ShutdownReason. if the value is BinDirChangeOrDirectoryRename, then some process is changing some files (create, delete, change attribute) in the application’s folder.
If you can’t find who is ding this, use Process Monitor from SysInternals. In my case, it was the antivirus process that was setting the files CreationTime (to their previous CreationTime!).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0