我已经创建了简单的WPF控件监测变化的日志文件。我用FileSystemWatcher的观看特定的文件。我的配置:
I've created simple WPF control to monitor changes in log file. I used FileSystemWatcher to watch specific file. My configuration:
Directory = System.IO.Path.GetDirectoryName(logFileFullPath);
Filter = System.IO.Path.GetFileName(logFileFullPath);
NotifyFilter = (NotifyFilters.LastWrite | NotifyFilters.Size);
EnableRaisingEvents = true;
的问题是,变化只手动或开口日志文件刷新目录后显示。
The problem is that changes are displayed only after refreshing the directory manually or opening log file.
我用RollingFileAppender进行在我log4net的配置,这样的改变,应立即书面。
I use RollingFileAppender in my log4net configuration so changes should be written immediately.
现在的问题是:为什么不到风度它的工作,以及如何使其工作
The question is: why dosn't it work and how to make it work?
编辑:
此外,当我手动更新等监视的文件观察者工作正常。因此,它必须有一些log4net的问题。
Also when I update manually other monitored file the watcher works fine. So it must be some log4net issue.
我终于想出了解决办法。这个问题有一点做与FileSystemWatcher的。我log4net的配置是缺乏行:
I've finally come up with solution. The problem had little to do with FileSystemWatcher. My log4net configuration was lacking the line:
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
这还是挺有意思的,因为我曾与从文本编辑器中打开日志文件中没有任何问题。
It's still quite interesting as I had no problem with opening log file from text editor.