INFO: App.LogEvent Only Logs in Compiled Applications
ID: Q161306
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
SUMMARY
In Microsoft Visual Basic, Event Logging allows an application to add
information to either a user-defined file or the Microsoft Windows NT Event
Log when a user-defined criteria is met.
This functionality is only available when running a compiled application.
If you attempt to use the logging methods while in the Microsoft Visual
Basic development environment, the logging methods will be ignored.
MORE INFORMATION
The logging can be enabled for the development process by creating and
compiling a user-defined ActiveX DLL or EXE component that exposes the
logging methods of the App object. The application in the development
environment need only to add a reference to this compiled component.
Calling the exposed methods of this ActiveX component will allow logging
to function. Below is a sample ActiveX DLL that exposes the StartLogging
and LogEvent methods of the App object.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR
OWN RISK. Microsoft provides this code "as is" without warranty of any
kind, either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
- Start Microsoft Visual Basic. Open a new ActiveX DLL project. This will
add Class1 to the new project.
- Change the Name property of Class1 to "Logging" (without quotes).
- From the Project menu, click Project1 Properties.
- Change the Name of the Project to "AppMessages" (without quotes).
- Add the following code to the Logging class:
Public Enum eLogModes
mLogAuto = 0
mLogOff = 1
mLogToFile = 2
mLogToNT = 3
mLogOverwrite = &H10
mLogThreadID = &H20
End Enum
Public Sub StartLog(logTarget As String, logMode As eLogModes)
App.StartLogging logTarget, logMode
End Sub
Public Sub AddLogEvent(LogBuffer As String, EventType As _
LogEventTypeConstants)
App.LogEvent LogBuffer, EventType
End Sub
NOTE: Other methods may be exposed to apply to your specific needs. See the
Microsoft Visual Basic Online Help for the entire list of event log methods
of the App object.
- From the File menu, click Make AppMessage.DLL. Select a folder in which
to place the DLL, and click OK.
- From the File menu, click New project. Click Yes to Save the AppMessage
source code for later use.
- Select Standard EXE. Click OK.
- From the Project menu, click References.
- Turn on the reference to "AppMessages." Click OK.
- To Form1, add the following code:
Private Sub Form_Load()
Dim t As New AppMessages.Logging
t.StartLog "C:\TEMP\Test.log", mLogToFile
t.AddLogEvent "Form Loaded", vbLogEventTypeInformation
Set t = Nothing
End Sub
- From the Run menu, click Start. A new file "Test.log" will be created
and placed into the C:\TEMP folder. This file will contain the
information:
"Information Application C:\TEMP\Test.log: Thread ID: -316429 ,Logged:
Form Loaded"
REFERENCES
Microsoft Visual Basic 5.0 Online Help
"StartLogging Method"
"LogEvent Method"
Additional query words:
kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbActiveX
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbhowto
|