C#读取Windows日志

管理-->事件查看器

 
 
可以查看【应用程序】、【安全】、【系统】等分类的日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
static void Main(string[] args)
{
    EventLog eventlog = new EventLog();
    eventlog.Log = "Security";
    //"Application"应用程序, "Security"安全, "System"系统
    EventLogEntryCollection eventLogEntryCollection = eventlog.Entries;
    foreach (EventLogEntry entry in eventLogEntryCollection)
    {
        //if (entry.EventID == 4624)
        //{
        //    continue;
        //}
        string info = string.Empty;
        if (@"TaskScheduler" == entry.Source.ToString())
        {
            info += "类型:" + entry.EntryType.ToString() + ";";
            info += "日期" + entry.TimeGenerated.ToLongDateString() + ";";
            info += "时间" + entry.TimeGenerated.ToLongTimeString() + ";";
            info += "来源" + entry.Source.ToString() + ";";
            Console.WriteLine(info);
        }
    }
}



 

 

posted @ 2016-03-07 11:54    阅读(7491)  评论(0编辑  收藏  举报