我正在" w3svc1"上运行一个filesystemwatcher。文件夹,默认情况下存储iis日志。当我去地址localhost或我的webapp localhost / xxxxx的任何人。 filesystemwatcher不会引发事件。我知道请求和日志中的写入之间存在延迟,但即使在一小时后也没有发生更改事件。但是,当我用notepad ++打开文件时,我看到添加了日志。有没有人有解释。这是我的代码:
class Program
{
static void Main(string[] args)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\inetpub\logs\LogFiles\W3SVC1";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.IncludeSubdirectories = true;
watcher.Filter = "*.log";
watcher.Changed += new FileSystemEventHandler(OnChangedok);
watcher.Created += new FileSystemEventHandler(OnChangedok);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
private static void OnChangedok(object source, FileSystemEventArgs e)
{
Console.WriteLine(e.FullPath);
}