How do I read events in event viewer from vb.net or have events automatically sent to a database for parsing?

Posted on 2011-09-20
Medium Priority
Last Modified: 2012-05-12
Hello.  So what I need to do is for a project i'm developing I need to be able to parse new events in the security log from event viewer.  One option is to manually export the log to a csv format and that is all nice but I need something automated.  I'd rather not have to export into csv and be able to parse through the events in realtime on an as needed basis but I don't know if that is possible.

is it possible to query the security log in event viewer and parse individual log entries?  the server with event viewer is a 2008 R2 machine.  my application can sit and run on that server and retrieve the data locally.  

thanks for any assistance.
Question by:linuxrox
LVL 14

Accepted Solution

athomsfere earned 1200 total points
ID: 36567206
If you can convert this from C# to VB.net here is something I wrote a while back.

        private void getSystemErrors()
            String computerName = txtComputer.Text;

            EventLog eventEntry = new EventLog("System", computerName);

            foreach (EventLogEntry entry in eventEntry.Entries)
                if (entry.EntryType == EventLogEntryType.Error)
                    lstEvents.Items.Add(entry.TimeGenerated + " " + entry.Source
                       + " " + entry.Category );

Open in new window

Changs "System" to "Security", and then what that does is add each Error level event on a remote machine to a listbox. You can remove the computername overload and it will run locally.
LVL 17

Assisted Solution

nepaluz earned 800 total points
ID: 36568826
here' a literal VB conversion
Sub GetSystemErrors()
    Dim eRrorEvents As New List(Of String)
    Dim ComputerName As String = My.Computer.Name
    Dim eVententry As EventLog = New EventLog("System", ComputerName)
    For Each entry As EventLogEntry In eVententry.Entries
        If entry.EntryType = EventLogEntryType.Error Then
            eRrorEvents.Add(String.Join(", ", {entry.TimeGenerated, entry.Source, entry.Category}))
        End If
End Sub

Open in new window


Author Closing Comment

ID: 36569151
very much appreciated guys!

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
Six Sigma Control Plans
Starting up a Project

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question