Article ID: 161306 - Last Review: May 13, 2003 - Revision: 2.0

INFO: App.LogEvent Only Logs in Compiled Applications

This article was previously published under Q161306
Expand all | Collapse all

SUMMARY

In Microsoft Visual Basic, Event Logging allows an application to add information to either a user-defined file or the Microsoft Windows NT or Windows 2000 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.
  1. Start Microsoft Visual Basic. Open a new ActiveX DLL project. This will add Class1 to the new project.
  2. Change the Name property of Class1 to "Logging" (without quotes).
  3. From the Project menu, click Project1 Properties.
  4. Change the Name of the Project to "AppMessages" (without quotes).
  5. 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.
  1. From the File menu, click Make AppMessage.DLL. Select a folder in which to place the DLL, and click OK.
  2. From the File menu, click New project. Click Yes to Save the AppMessage source code for later use.
  3. Select Standard EXE. Click OK.
  4. From the Project menu, click References.
  5. Turn on the reference to "AppMessages." Click OK.
  6. 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
    
    					
  7. 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"

APPLIES TO
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Control Creation Edition
Keywords: 
kbinfo KB161306
 

Article Translations