Blue Theme Orange Theme Green Theme Red Theme
 
Click Here for 3 Month Free of ASP.NET Hosting!
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Windows Forms » 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:
Technologies: .NET 3.0 and 3.5, Windows Forms,Visual C# .NET
Total downloads : 215
Total page views :  4199
Rating :
 3/5
This article has been rated :  2 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
EnhancedEventViewer.zip
 
Become a Sponsor


Related EbooksTop Videos


 

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.

 


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Sateesh Kumar
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.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
EnhancedEventViewer.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Powerful ASP.NET Hosting w/ NO Setup Fees. Click Here!
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved