码迷,mamicode.com
首页 > 其他好文 > 详细

获取系统日志信息

时间:2019-01-21 19:10:55      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:知识   ati   信息   log   ext   class   http   trie   count   

实现效果:

  技术分享图片

知识运用:

  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 += "\n\n 类型:"+entry.EntryType;                         
                info += "\n\n 日期:" + entry.TimeGenerated.ToLongDateString();  
                info += "\n\n 时间:" + entry.TimeGenerated.ToLongTimeString();
                info += "\n\n 来源:" + entry.Source;
                info += "\n\n 事件:" + entry.EventID.ToString();
                info += "\n\n 用户:" + entry.UserName;
                info += "\n\n计算机:" + entry.MachineName;
            }
            richTextBox1.Text = info;                                           //显示日志信息
        }

  

获取系统日志信息

标签:知识   ati   信息   log   ext   class   http   trie   count   

原文地址:https://www.cnblogs.com/feiyucha/p/10300138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!