Chapter 20. Writing to the Event Log

Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Part IV.  Building Web Services


In This Chapter

  • Managing an Event Source

  • Writing Events to an Existing Log

  • Writing to a Custom Event Log

  • Getting the Contents of an Event Log

  • Clearing an Event Log

  • Receiving Event Notifications

  • Using a Remote Event Log

  • Using EventLogTraceListener

  • Summary

A common technique employed before integrated debuggers were popularized was to write application trace information to the console. An evolution of this process was to write application information to a text file. This is a strategy still employed today. Windows NT 4.0, 5.0 (2000), and XP use an event log to track significant system, security, and application information.

Visual Basic .NET supports a general logging strategy based on the Windows 2000 EventLog. An event log is a file with a .evt extension. The three common event logs used in the Event Viewer are Application, System, and Security. (These files can be found on your computer as AppEvent.evt, SecEvent.evt, and SysEvent.evt.)

You can use the EventLog class in the Common Language Runtime from Visual Basic .NET to write significant application information and a custom event log for tracing of debugging messages during development. It's not a recommended practice to write line items to existing logs, like the Application log, but you can employ a custom event log during development and testing. Using EventLog is a superior approach to logging application and debugging information relative to creating a custom solution.

This chapter demonstrates how to use the enhanced capabilities of the EventLog class, and how to use the EventLogTraceListener. The EventLogTraceListener allows you to make the EventLog and a custom log source a recipient of Trace messages.

Caution

Before experimenting with the examples in this chapter, run the Registry Editor (regedit.exe or regedt32.exe) and export a copy of your registry. If you run into any problems, you can use the exported registry to restore your settings.



Team-Fly    
Top
 


Visual BasicR. NET Unleashed
Visual BasicR. NET Unleashed
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 222

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net