zl程序教程

您现在的位置是:首页 >  工具

当前栏目

获取安全日志信息

日志安全 获取 信息
2023-09-14 08:58:58 时间

实现效果:

  

知识运用:

  EventLog类的Log属性  Entries属性  

  EventLogEntryCollection类的Count属性 及 EventLogEntry类的相关属性

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            this.eventLog1.Log = "Security";
            EventLogEntryCollection collection = eventLog1.Entries;
            string info = "显示安全性日志" + collection.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;
        }