我正在部署的网站是使用log4net将消息记录到日志文件,每次尝试部署新版本的代码时,我在Visual Studio中收到此错误,指出当前的log4net日志文件正在使用中:
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.
我可以通过上传到服务器并在发布之前做一个iisreset来解决这个问题,但是这样可以打败Visual Studio的“容易”发布的一点:)
解决方法
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
对您的< appender> web.config文件中的元素?从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.
就性能考虑而言,假设您需要测试这是否会影响到您,因为我假设它确实取决于您写入日志文件的频率,这会影响性能.我不能相信获取/释放锁可能需要很多时间.