某个程序在运行的过程中会不停地在它的日志文件里面写程序的操作日志,那我现在需要在这个程序运行的过程中,从它的日志里同步地读取出这些操作日志作分析,请问各位大虾这个用C#如何做?

解决方案 »

  1.   

    http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
      

  2.   

    filesystemwatcher这个类可以在达到效果,具体你可参考
    http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
      

  3.   

       // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();
            /// <summary>
            /// 监听文件夹
            /// </summary>
            public void ThreadDirectory()
            {            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);             System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
                if (dirs.Length > 0)
                {
                    //直接走
                    Send();
                }
                else
                {
                    watcher.Path = path;
                    watcher.IncludeSubdirectories = true;
                    //监听类型
                    watcher.NotifyFilter = NotifyFilters.FileName;
                    //监听该文件夹中的所有文件
                    watcher.Filter = "*.*";
                    // 执行操作   当文件创建的时候触发事件                watcher.Created += new FileSystemEventHandler(watcher_Created);
                    // 启用监听
                    watcher.EnableRaisingEvents = true;
                }
            }
             void watcher_Created(object sender, FileSystemEventArgs e)
            {
                Send();
            }调用:
     Thread t1 = new Thread(ThreadDirectory);
                    t1.Start();//线程开启
      

  4.   

        if (dirs.Length > 0)
                 {
                     //直接走
                     Send();
                 }我的是 判断如果文件夹里有文件就直接读取,没有的话等待文件创建然后触发事件走else