zoukankan      html  css  js  c++  java
  • 获取系统日志信息

    实现效果:

      

    知识运用:

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

      public string Log ( get;  set;)   //属性值: 日志的名称  Application System 和 Security或其他自定义 默认为(“”);

      public EventLogEntryCollection Entries { get; }  //获取日志事件的内容  属性值:EventLogEntryCollection集合

      EventLogEntryCollection类的Count属性

      public int Count {  get;  }    //获取事件日志中的项数即 EventLogEntry集合中的元素个数

      EventLogEntry类的相关属性    //该类用来在事件日志中封装单个记录

      

    实现代码:

            private void button1_Click(object sender, EventArgs e)
            {
                this.eventLog1.Log = "System";                                      //设置获取系统日志
                EventLogEntryCollection collection = eventLog1.Entries;             //创建日志实体对象
                int count = collection.Count;                                       //获取所有日志条数
                string info= "系统日志数:" + count+"个";                            //显示日志条数
                foreach(EventLogEntry entry in collection)                          //遍历获取到的日志
                {
                    info += "
    
     类型:"+entry.EntryType;                         
                    info += "
    
     日期:" + entry.TimeGenerated.ToLongDateString();  
                    info += "
    
     时间:" + entry.TimeGenerated.ToLongTimeString();
                    info += "
    
     来源:" + entry.Source;
                    info += "
    
     事件:" + entry.EventID.ToString();
                    info += "
    
     用户:" + entry.UserName;
                    info += "
    
    计算机:" + entry.MachineName;
                }
                richTextBox1.Text = info;                                           //显示日志信息
            }
    

      

  • 相关阅读:
    webpack4 plugins 篇
    webpack4 打包静态资源
    babel 7 简单指北
    JS: 深拷贝
    JS: 数组的循环函数
    async await 的执行
    redux
    TCP通信
    理解Javascript的原型和原型链
    「译」forEach循环中你不知道的3件事
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10300138.html
Copyright © 2011-2022 走看看