zoukankan      html  css  js  c++  java
  • 使用FileSystemWatcher组件监视日志文件

    实现效果:

      

    知识运用:

      FileSystemWatcher组件的Path属性

      Filter属性    //要监视那些文件   默认为*.* 

      Endinit方法    //结束在窗体上使用或有另一个组件使用的FileSystemWatcher的初始化

      Created Changed Deleted 事件 

    实现代码:

            private void button1_Click(object sender, EventArgs e)
            {
                button1.Enabled = false;
                fileSystemWatcher1.Path = textBox1.Text;        //设置要监视的文件的路径
                fileSystemWatcher1.Filter = "*.Evt";            //获取或设置要筛选的字符串
                fileSystemWatcher1.EndInit();           //结束fileSystemWatcher1的初始化过程
            }
    
            private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
            {
                listBox1.Items.Add("日志文件" + e.FullPath + "被更改");
            }
    
            private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
            {
                listBox1.Items.Add("日志文件" + e.FullPath + "被创建");
            }
    
            private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
            {
                listBox1.Items.Add("日志文件"+e.FullPath+"被删除");
            }
    
        }
    
  • 相关阅读:
    宝藏 题解
    Xorequ 题解
    2020.12.26 模拟赛 题解
    数据结构 100 题 1~10 线段树
    关于模拟退火
    诗意狗 题解
    Keyboading 思路
    体育成绩统计/ Score
    【(抄的)题解】P5686 [CSP-SJX2019]和积和
    【笔记】简单博弈
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10198647.html
Copyright © 2011-2022 走看看