我在“w3svc1”文件夹上运行一个文件系统观察程序,默认情况下存储 iis 日志。当我转到地址 localhost 或我的 webapp localhost/xxxxx 的任何人时。文件系统观察器不会引发事件。我知道请求和写入日志之间存在延迟,但即使在一小时后也没有引发任何更改事件。但是,当我用 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);
}