Solved

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
3
365 Views
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.
0
Comment
Question by:linuxrox
3 Comments
 
LVL 14

Accepted Solution

by:
athomsfere earned 300 total points
Comment Utility
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.
0
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 200 total points
Comment Utility
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
    Next
End Sub

Open in new window

0
 

Author Closing Comment

by:linuxrox
Comment Utility
very much appreciated guys!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now