INFO: App.LogEvent Only Logs in Compiled Applications

Last reviewed: March 21, 1997
Article ID: Q161306
The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions, for Windows, version 5.0

SUMMARY

Microsoft Visual Basic version 5.0 introduces the concept of Event Logging to applications. This feature 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 5.0 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"


Additional query words: limit limitation
Keywords : kbusage vb5all vb5howto VBKBAX kbhowto
Technology : kbole
Version : 5.0
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.