Article ID: 154576 - Last Review: July 15, 2004 - Revision: 3.2 How To Write to the Windows NT Event Log from Visual Basic
This article was previously published under Q154576 On This PageSUMMARY
Event logging in Windows provides a standard, centralized way for Windows
and any other applications to record important software and hardware
events. It also supplies a standard user interface for viewing the logs and
a programming interface for examining the logs.
This article illustrates how to write to the NT or Windows 2000 Event Log with Visual Basic versions 4.0 and later. With Visual Basic version 4.0, you must use the Win32 API. Visual Basic versions 5.0 and later have built-in functionality for event-logging so the API functions are unnecessary. MORE INFORMATIONVisual Basic versions 5.0 and LaterVisual Basic versions 5.0 and later expose three methods and properties of the App object by which event-logging can be enabled:
LogMode Property
The LogMode property returns a value that determines how logging (through
the LogEvent method) will be carried out. (Read-only at run time).
LogPath Property LogEvent Method The LogPath property returns the path and filename of the file used to capture output from the LogEvent method. (Read-only at run time). The LogEvent method writes an event into the application's log target. On Windows NT or Windows 2000 platforms, the method writes to the NT or Windows 2000 Event log. On Windows 95, Windows 98, and Windows Me platforms, the method writes to the file specified in the LogPath property; by default, if no file is specified, events will be written to a file named vbevents. The Event Log only updates when your application is running as a compiled .EXE. It will not write events to the Event log when run from the IDE. This is to prevent excessive data from being written to the Event Log during debugging. Visual Basic 4.0 (32-bit)The following example shows how to send three different types of events. These steps are for applications written with Visual Basic 4.0 only.Information, Warnings, and Errors:
REFERENCES
For additional information, please click the article numbers below
to view the articles in the Microsoft Knowledge Base:
184747
(http://support.microsoft.com/kb/184747/EN-US/
)
INFO: Event Logging in Visual Basic
Microsoft Developer Support Network (MSDN)
161306 (http://support.microsoft.com/kb/161306/EN-US/ ) INFO: App.LogEvent Only Logs in Compiled Applications 161283 (http://support.microsoft.com/kb/161283/EN-US/ ) INFO: Default Filename for Text File Error Log: VBEVENTS.LOG Platform SDK; Reference; Functions -- Win32 Functions Microsoft Visual Basic 5.0 Online Help APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
