O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Write to the Windows Event Log

Problem

You need to write a log entry to the Windows event log on the current computer.

Solution

Register the event source and create the log if required. Write the message using the System.Diagnostics.EventLog class.

Discussion

The EventLog class makes it easy to write and retrieve event log entries. You create an EventLog instance that wraps a specific log—typically the all-purpose Application log or a custom log that’s used by your application.

' Access the Application log.
Dim Log As New EventLog("Application")

You can also supply an additional argument to the EventLog constructor to specify a computer name. This allows you to access an event log defined on another computer on the network.

' Access the Application log. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required