Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web deployment failing due to file in use

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?

like image 932
Cocowalla Avatar asked Apr 23 '13 16:04

Cocowalla


People also ask

How do I know if web Deploy is running?

Is Web Deploy installed? You can verify web deploy is installed by going to the "Programs and Features" control panel and looking for "Microsoft Web Deploy 2.0" in the list of installed programs. If it is not there, you can install it via the Web Platform Installer by going to the "Products" tab.

Can't connect to remote server web Deploy?

This error indicates that you cannot connect to the server. Make sure the service URL is correct,firewall and network settings on this computer and on the server computer are configured properly,and the appropriate services have been started on the server.

What is web deployment?

What is Web Deploy? Web Deploy is an extensible client-server tool for syncing content and configuration to IIS. Web Deploy is used primarily in two scenarios: Developers use it to sync (aka 'publish') a compiled web applications (ASP . Net, PHP etc) from developer tools (Visual Studio, WebMatrix, etc) to IIS.


2 Answers

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.

like image 60
Tommy Avatar answered Oct 09 '22 13:10

Tommy


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.

like image 35
Shaikh Owais Avatar answered Oct 09 '22 12:10

Shaikh Owais