read the windows event log by particular Source

2019-07-01 13:13发布

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

3条回答
爷的心禁止访问
2楼-- · 2019-07-01 13:39

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.

查看更多
Explosion°爆炸
3楼-- · 2019-07-01 13:49

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!

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-07-01 13:52

You could use additional software called "Log Parser"

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

查看更多
登录 后发表回答