进程无法访问文件" MyFile.log"因为它正被另一个进程 [英] Process cannot access the file "MyFile.log" because it is being used by another process
问题描述
我收到
该进程无法访问文件MyFile.log,因为它正由另一个进程使用。
The process cannot access the file "MyFile.log" because it is being used by another process.
而我这样做
File.SetAttributes(filename,FileAttributes.Normal)
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Do stuff with log4net log
}
我已阅读其他职位,但他们都暗示什么,我已经在做。任何其他建议?
I have read other posts but they all suggest what I am already doing. Any other suggestions?
感谢。
推荐答案
尝试配置log4net的一个最小的锁:
Try to configure log4net with a minimal lock:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
...
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
...
</appender>
另外,尝试与打开日志文件:
Alternatively, try to open the log file with:
using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
{...
}
或检查项目: Tailf 在任何情况下,删除该SetAttributes()的一部分,可能无法正常工作。 Tailf项目简介 Tailf是一个C#实现尾-f命令可在UNIX / Linux系统。以不同的方式形成其他端口不锁定以任何方式文件,因此它的工作原理,即使其他文件重命名为:这是expecially设计很好地与log4net的滚动文件Appender的作品的
or check this project:Tailf In any case, remove the SetAttributes() part that could not work. Tailf Project Description Tailf is a C# implementation of the tail -f command available on unix/linux systems. Differently form other ports it does not lock the file in any way so it works even if other rename the file: this is expecially designed to works well with log4net rolling file appender.
这篇关于进程无法访问文件&QUOT; MyFile.log&QUOT;因为它正被另一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!