看着log4net的日志文件,FileSystemWatcher的 [英] Watching log4net log file with FileSystemWatcher

查看:218
本文介绍了看着log4net的日志文件,FileSystemWatcher的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了简单的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.

这篇关于看着log4net的日志文件,FileSystemWatcher的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆