The System.Diagnostics Event Log Interface

The event log interface in the System.Diagnostics namespace is very feature-complete; this namespace is the one discussed and used in all the code examples in this chapter. Despite its extra features, the EventLog object in the System.Diagnostics namespace is quite easy to manipulate and use. To write a message to the Windows 2000 Event Log, simply call the static WriteEntry method of the EventLog class as illustrated in Listings 8.1 and 8.2.

Listing 8.1. Writing to the Event Log Using the EventLog object in System.Diagnostics (C#)
<%@ Page Language="C#" %> 
<%@ Import Namespace="System.Diagnostics" %> 

<% 
     EventLog.WriteEntry("EventTest", 
          "I'm a little teapot, short and stout."); 
     Response.Write("Done!"); 
%> 

Listing 8.2. Writing to the Event Log Using the EventLog object in System.Diagnostics (Visual Basic .NET)
<%@ Page Language="VB" %> 
<%@ Import Namespace="System.Diagnostics" %> 

<% 
    EventLog.WriteEntry("EventTest", _ 
         "I"m a little teapot, short and stout.") 
    Response.Write("Done!") 
%> 

Figure 8.1 shows how the event that you just logged would look when viewed in the Windows 2000 Event Log Viewer.

Figure 8.1. Double-clicking an event in the Windows 2000 Event LogViewer displays its details in a property page dialog box.


Notice that you can specify a source EventTest for the event that appears in the Source field of the Windows 2000 Event Log Viewer. The EventLog object gives you a great deal of power and control over the Windows 2000 Event Log. It also enables you to create custom event logs and to control event logs on other machines on your network (discussed next), among other things.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset