Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » Windows Forms C# » Enhanced Event Viewer in VS 2008

Enhanced Event Viewer in VS 2008

This application developed using Windows Forms and C# in an extend event viewer and provides many useful features that are not present in built-in Windows Event Viewer.

Author Rank :
Page Views : 7921
Downloads : 376
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
EnhancedEventViewer.zip
 
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


 

Windows provides a nice tool for viewing event logs of our machine. This tool called as Event Viewer is having lot of features to browse through our event logs. Even though, it is a very useful tool to browse our event log, but it does not provide certain features like searching and auto-show up of new events etc. So, I thought of doing an application that makes our event log browsing faster and much easier. First, I will explain the features provided by it followed by design and coding,

 

Features provided by this Viewer:

 

Ø      Easy to navigate among the Logs.

Ø      Easy to filter events.

Ø      Easy to do Search.

Ø      Click away to access it.

Ø      Connect to remote machine’s Event Log.

Ø      Listener to show new event entry automatically.

Ø      Better User Experience and lot more.

 

I designed this application in VS 2008 SP1.

 

Create a new Windows application in C# and name it as EnhancedEventViewer. Add the controls to EventViewer form as shown below:

 

Purpose of above controls:

 

v     ListView (lvEvents) à To list event details like message, event type etc.

v     TreeView (tvEventNodes) à To list all event logs on our machine.

v     MainMenu  Ã  To allow user to connect to a remote machine, refresh and clean event logs.

v     NotifyIcon à To show/hide the Event Viewer.

v     txtSearchText à To filter events based on search criteria.

v     ImageList à To display icon based on event type like warning, error etc.

 

We are done with the design. Now, let's dig into the functionality part of this application.  I will outline the steps performed by it.

 

1)      When we run the application, it loads all event logs of our machine.

2)      Based on selected Event log, it will list all the events of it.

3)      We can do a search by using Search textbox. It will filter events based on its Message property.

4)      We can connect to a remote machine, by entering machine name or IP address and pressing Enter. We need permissions on the remote machine to get connected.

 

Let's go into the coding part. I will outline the important methods.

 

v     LoadEventLogs à This method loads all event logs of a machine.

v     LoadEventDetails à This method loads all events of an event log. This will internally calls LoadThreadEventDetails to load events on a separate thread.

v     log_EntryWritten à This event will be raised on arrival of a new event in particular event log.

 

I will explain the core method (LoadThreadEventDetails) for loading events. In order to make application respond to user interactions while loading, I had implemented it on a separate thread using ThreadStart and Thread classes.

 

    private void LoadThreadEventDetails(string logName)

        {

            lock (logs)

            {

                try

                {

                    EventItems.Clear();

                    foreach (EventLog log in logs)

                    {

                        if (log.LogDisplayName == logName)

                        {

                           foreach (EventLogEntry entry in log.Entries)

                            {

                                ListViewItem item = new ListViewItem();

                                item.Text = entry.EntryType.ToString();

                                if (item.Text.StartsWith("Inform"))

                                {

                                    item.StateImageIndex = 0;

                                }

                                else if (item.Text.StartsWith("Error"))

                                {

                                    item.StateImageIndex = 1;

                                }

                                else if (item.Text.StartsWith("Warn"))

                                {

                                    item.StateImageIndex = 2;

                                }

                                else

                                {

                                    item.StateImageIndex = 1;

                                }

                                item.SubItems.Add(entry.Message.ToString() == "" ? "None" : entry.Message.ToString());

                                item.SubItems.Add(entry.TimeWritten.ToShortDateString());

                                item.SubItems.Add(entry.TimeWritten.ToLongTimeString());

item.SubItems.Add(entry.Source);

                                item.SubItems.Add(entry.InstanceId.ToString());

item.SubItems.Add(entry.UserName == null ? "N\\A" : entry.UserName);

item.SubItems.Add(entry.MachineName);

item.ToolTipText = entry.Message;

m_AddEventEntry = new AddEventEntry(this.AddEntry);

EventItems.Add(item);

this.Invoke(m_AddEventEntry, (new object[] { item }));

                            }

m_AddEventEntry = new AddEventEntry(this.AddEntry);

ListViewItem tempItem = new ListViewItem();

tempItem.Text = "!!!!";

this.Invoke(m_AddEventEntry, (new object[] { tempItem }));

break;

                        }

                    }

                }

                catch { }

            }

        }

 

Here, we are getting the events of a particular log and adding it to list view for display. Then, we are getting new event notification by adding EntryWrittenEventHandler for a log. Finally, we are displaying message of the selected event in a textbox for easy viewing.

 

I added some more code to improve the UI and functionality. Finally, the application looks like below:

 

 

We can still enhance this application by adding UI and extra functionality like saving/exporting event logs, better performance etc. I am attaching source code for reference. I hope this article will be helpful for all.

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Sateesh Arveti
I hold Bachelors degree in Computer Science along with MCSD,MCTS and MVP for the year 2009. Areas of Interest: C#, WPF, WF, silverlight, ASP.NET, Oracle and SQL Server.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.