VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This module allows you to write text to the Windows Event Log with with a single method call. Inclu

by Antonio Zavala (2 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 22nd October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This module allows you to write text to the Windows Event Log with with a single method call. Includes options for Type, Source, Category, and

API Declarations


Usage:
LogEvent([Applicaiton Name], [EventLog Type], [Msg to be logged], [Optional Event ID], [Optional Category Number])

Dim ret as Long
ret = LogEvent("TestApp1", EVENTLOG_SUCCESS, "Success event!!!!")



Rate This module allows you to write text to the Windows Event Log with with a single method call. Inclu



'Information compiled from MSDN Articles on Platform SDK: Debugging and Error Handling
'MSDN Home >  MSDN Library >  SDK Documentation >  Event Logging > _
'  Event Logging Reference >  Event Logging Functions
'
'FUNCTIONS:
'Public Function LogEvent(strSource As String, dEventType As Long, _
'    strError As String, Optional iEventID As Integer = 26, _
'    Optional iCategory As Integer = 26) As Long
'
'   returns nonzero for success otherwize zero for fail
'
'Module by Antonio Zavala, [email protected]
'United Services Automobile Association, 10/2002

Private Declare Function RegisterEventSource Lib "advapi32" Alias _
    "RegisterEventSourceA" (ByVal lpUNCServerName As String, ByVal lpSourceName As String) As Long

Private Declare Function DeregisterEventSource Lib "advapi32" _
    (ByVal hEventLog As Long) As Boolean

Private Declare Function ReportEvent _
    Lib "advapi32" Alias "ReportEventA" _
    (ByVal hEventLog As Long, _
    ByVal wType As Long, _
    ByVal wCategory As Long, _
    ByVal dwEventID As Long, _
    ByVal lpUserSid As Long, _
    ByVal wNumStrings As Long, _
    ByVal dwDataSize As Long, _
    lpStrings As Any, _
    lpRawData As Any) As Long

'   Event Type Constants
Public Const EVENTLOG_SUCCESS = &H0            'Success event
Public Const EVENTLOG_ERROR_TYPE = &H1         'Error event
Public Const EVENTLOG_WARNING_TYPE = &H2       'Warning event
Public Const EVENTLOG_INFORMATION_TYPE = &H4   'Information event
Public Const EVENTLOG_AUDIT_SUCCESS = &H8      'Success audit event
Public Const EVENTLOG_AUDIT_FAILURE = &H10     'Failure audit event

Public Function LogEvent(strSource As String, dEventType As Long, strError As String, Optional iEventID As Integer = 26, Optional iCategory As Integer = 26) As Long
'   returns nonzero for success otherwize zero for fail
Dim ret1, ret2, hEvt As Long
hEvt = RegisterEventSource(vbNullChar, strSource)
If hEvt Then
    ret1 = ReportEvent(hEvt, dEventType, iCategory, iEventID, 0, 1, 0, strError, vbNullChar)
    If Not ret1 Then
        LogEvent = 0
        Exit Function
    End If
End If
LogEvent = DeregisterEventSource(hEvt)
End Function

Download this snippet    Add to My Saved Code

This module allows you to write text to the Windows Event Log with with a single method call. Inclu Comments

No comments have been posted about This module allows you to write text to the Windows Event Log with with a single method call. Inclu. Why not be the first to post a comment about This module allows you to write text to the Windows Event Log with with a single method call. Inclu.

Post your comment

Subject:
Message:
0/1000 characters