I have an app running in its own app pool that writes often to a text log file. When the 29-hour fixed recycle hits, I usually run into problems because the new process is launched while the old process is still there. This causes "can't open the file because it's in use by another process."
First I simply tried to set Disable Overlapped Cycle to True, but that takes my service off the air for 90 seconds or more, which is not good. If I reduce the Shutdown Time Limit I suppose it would help, but I'd prefer not to kill the process immediately.
I tried setting up an Application_End
handler in Global.asax, but I find it's almost never getting called because (I think) my process is still running a thread somewhere (possibly the logging process).
I tried Application_Disposed
but so far it does not get called when IIS kills the process after the shutdown time expires, and it's probably too late by then if I go back to overlapped recycle, which I think is preferable.
What I need is a signal from IIS that says "Hey, I want you to stop," that lets me close the log file immediately, but that does not seem to exist.
Any suggestions would be appreciated.