15.3. Write an Event to the Windows Event Log

Problem

You need to write an event to the Windows event log.

Solution

Use the members of the System.Diagnostics.EventLog class to create a log (if required), register an event source, and write events.

How It Works

You can write to the Windows event log using the Shared methods of the EventLog class, or you can create an EventLog object and use its members. Whichever approach you choose, before writing to the event log, you must decide which log you will use and register an event source against that log. The event source is simply a string that uniquely identifies your application. An event source may be registered against only one log at a time.

By default, the event log contains three separate ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.