read the windows event log by particular Source

时间秒杀一切 提交于 2019-12-23 18:22:47

问题


How can i read the windows event log by particular Source, Date time and category??


回答1:


Consider using EventLog Class.

EventLog lets you access or customize Windows event logs, which record information about important software or hardware events. Using EventLog, you can read from existing logs, write entries to logs, create or delete event sources, delete logs, and respond to log entries. You can also create new logs when creating an event source.




回答2:


You could use additional software called "Log Parser"

Comes with an API you can use, check the help file once installed :)




回答3:


I know this question is mighty old, but I spent a good deal of time today building a solution to this so I thought I would share:

        Dim myEventLogEntryCollection As EventLogEntryCollection = New EventLog("Application", System.Environment.MachineName).Entries

        Dim myEventLogEntryArray(myEventLogEntryCollection.Count - 1) As EventLogEntry

        myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0)

        Dim QueryLog As System.Linq.IQueryable(Of EventLogEntry) = myEventLogEntryArray.AsQueryable

        QueryLog = QueryLog.Where(Function(i As EventLogEntry) i.Source = "MyParticularSourceName")

        For Each Entry As EventLogEntry In QueryLog

            '... your code goes here

        Next

        myEventLogEntryCollection = Nothing
        myEventLogEntryArray = Nothing

Hope it helps others!



来源:https://stackoverflow.com/questions/2713456/read-the-windows-event-log-by-particular-source

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!