Microsoft KB Archive/184747

= INFO: Event Logging in Visual Basic =

Article ID: 184747

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition

-



This article was previously published under Q184747



SUMMARY
The App object in Visual Basic has the following methods and properties that facilitate the creation of event logs:   Methods: LogEvent, StartLogging.

Properties: AppMode, AppPath. This article addresses some of the common issues associated with these properties and methods and provides an event logging example that demonstrates their use.



Common Issues Regarding Event Logging

 * Event logging does not work within the Visual Basic IDE. To enable event logging, you must compile and run a Visual Basic project as an executable.
 * The LogPath and LogMode properties are read-only. The documentation in books online is incorrect in suggesting that they can be used as L-Values.
 * You can specify the LogPath and LogMode by using the logTarget and logMode parameters of the StartLogging method respectively.
 * If LogPath is not specified, the logged entries go to the event log on Windows NT and the VBEvents.log file in the %SystemRoot% directory on Windows 95 and Windows 98.
 * The Source in the Windows NT Event Viewer for all entries of any Visual Basic application is "VBRuntime." This is by design.

Event Logging Example
 Create a new a Standard EXE project (Project1) in Visual Basic (Form1 is created by default). Add two Command buttons to Form1.  Add the following code to Form1's code window: '=========================== CODE FOR FORM1 ==========================

Private Sub Command1_Click 'Default logging without specifying LogPath or LogMode. With App .LogEvent "Default Logging " & Now, vbLogEventTypeInformation .LogEvent .LogPath .LogEvent .LogMode End With End Sub

Private Sub Command2_Click 'Logging to a file by specifying LogPath and LogMode 'in the StartLogging method call. With App .StartLogging "c:\temp\logtest.log", 2 'LogMode = 2 should be the same as vbLogToFile, 'but vbLogToFile constant is not defined as shown 'in books online. .LogEvent "Specified Path File Logging " & Now, vbLogEventTypeInformation .LogEvent .LogPath .LogEvent .LogMode End With End Sub

Private Sub Form_Load Command1.Caption = "Default Logging" Command2.Caption = "Specified Path" End Sub '======================== END OF CODE FOR FORM1 =======================  Compile the project. Run the resulting Executable file, and press the command buttons to generate the logs. Check the logs. If you are using Windows 2000 or Windows NT, check the default logging with the Event Viewer by selecting Application from the Log menu, then press the F5 key to refresh. If you are using Windows 95, Windows 98, or Windows Me, you can find VBEvents.log in the %SystemRoot% directory on Windows 95 and Windows 98, typically the C:\Win95 or C:\Windows directory. The non-default log file (LogTest.log) for both platforms should be in the "C:\Temp" directory.

Additional query words: LogPath LogMode StartLogging LogEvent

Keywords: kbinfo KB184747

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.