zoukankan      html  css  js  c++  java
  • 使用EventLog组件保存Windows系统日志

    实现效果:

      

    知识运用:

      EventLog类的CreateEventSource方法  //用于建立一个应用程序  使用指定的Sourc作为向本机上的日志中写入日志项的有效事件源 

      CreateEventSource(string source,string logName)    //亦可以在本机上创建一个新的自定义日志

      Log属性    //获取或设置在读取或写入的日志名称

        public string Log{get;set;}

      Source属性  //获取或设置在写入事件日志时要注册和使用的源名称

      public string Source{get;set;} 

    实现代码:

            private void Form1_Load(object sender, EventArgs e)
            {
                if (System.Diagnostics.EventLog.SourceExists("ErrEventLog"))
                {
                    System.Diagnostics.EventLog.DeleteEventSource("ErrEventLog");
                }
                System.Diagnostics.EventLog.CreateEventSource("ErrEventLog","Application");
                eventLog1.Log = "Application";
                eventLog1.Source = "ErrEventLog";
                eventLog1.MachineName = ".";
            }
    
            private void btn_find_Click(object sender, EventArgs e)
            {
                if (eventLog1.Entries.Count>0)
                {
                    foreach(System.Diagnostics.EventLogEntry evn in eventLog1.Entries )
                    {
                        if (evn.EntryType == System.Diagnostics.EventLogEntryType.Error)
                            listBox1.Items.Add(evn.Message);
                    }
                }
                else { MessageBox.Show("系统没有错误日志"); }
            }
    
  • 相关阅读:
    cf 559a **
    poj 2599 单调栈 ***
    Unicode(UTF-8, UTF-16)令人混淆的概念
    Uber Go 语言编程规范
    深入理解 Go Channel
    如何使用 GZIP 来优化网站
    跨域资源共享 CORS 详解 [转载]
    使用dig查询DNS解析过程
    golang 实现简单DNS服务器
    一文看懂JS的异步
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10191775.html
Copyright © 2011-2022 走看看