Web deployment failing due to file in use
Asked Answered
C

2

9

I'm using Microsoft's Web Deploy Remote Agent service to allow me to easily publish code to the server from within Visual Studio.

The web site I am deploying is using log4net to log messages to log files, and every time I try to deploy a new version of the code, I get this error in Visual Studio stating that the current log4net log file is in use:

An error occurred when the request was processed on the remote computer. The file 'Web.log' is in use.

The process cannot access 'C:\inetpub\wwwroot\Logs\Web.log' because it is being used by another process.

I can solve this by going onto the server and doing an iisreset before publishing... but that is kind of defeating the point of 'easy' publishing from Visual Studio :)

Is there some way I can get the publish task to issue an iisreset automatically, or some other way I can work round this?

Couchman answered 23/4, 2013 at 16:44 Comment(4)
Is this your log4Net log file?Huzzah
@Huzzah Yes, sorry, I should make that clearer :)Couchman
I am wondering if you could tie into the Application_End event in your global.asax and call the shutdown option for log4Net. This should free up the lock on the file. I have not had to do this, thus not posted as an answer, but there are a few SO questions and other items related to shutting down the logging service for various other reasons.Huzzah
@Huzzah Tried it, but it didn't work. Application_End event doesn't seem to get called when publishing :(Couchman
H
9

I kept poking around and found some tidbits around the file being locked in a few other forums. Have you tried adding

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

To your <appender> element in the web.config file? From the Apache docs

Opens the file once for each AcquireLock/ReleaseLock cycle, thus holding the lock for the minimal amount of time. This method of locking is considerably slower than FileAppender.ExclusiveLock but allows other processes to move/delete the log file whilst logging continues.

As far as the performance considerations, I suppose you would need to test if this will affect you or not as I am assuming it really depends on how often you are writing to the log file as to how much this will impact performance. I can't believe that getting/releasing a lock could take all that much time though.

Huzzah answered 24/4, 2013 at 13:45 Comment(0)
Y
6

There is a MSDEPLOY provider called recycleApp which is used exactly for this. You can include this in your deployment manifest.

Another option is to use ignoreOnErrors flag which will skip the file in use and continue with the deployment.

Yachtsman answered 28/4, 2013 at 16:28 Comment(2)
Can you give some information on recycleApp and how to actually include this? I don't see any options in Visual Studio, same for ignoreOnErrors flagCouchman
You could run this command manually as a pre-deploy step or automated using a VS deployment step - check out AfterTargets="CopyAllFilesToSingleFolderForPackage". There isn't yet an option in VS to tell it to recycle the app - only file + SQL publish options.Blowy

© 2022 - 2024 — McMap. All rights reserved.