簡體   English   中英

檢測iis日志文件中的更改

[英]Detect changes in iis logs files

我在“ 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);         

    }

這是因為IIS打開了流並將日志寫入文件,但是沒有立即刷新更改。 當您在notepad ++中打開文件時,它會訪問該文件,從而觸發文件修改事件。 請同時參考此線程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM