How to register an event in the windows system Log ?

The system log allows programmer to store log from their application in a standard way.
To do so, you need to register an event source before registering the event itself.
The following is a simple example to register one message.

This function  adds a log entry to the system log
Param wEventType is one of the MSDN event type for ReportEvent (EVENTLOG_SUCCESS, EVENTLOG_AUDIT_FAILURE, EVENTLOG_AUDIT_SUCCESS, EVENTLOG_ERROR_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_WARNING_TYPE)
Param szMessage is the message to log.

void SystemLog( WORD wEventType, const char* szMessage )
{
const char* LOCAL_HOST = NULL;
if ( HANDLE hEventSource = RegisterEventSource( LOCAL_HOST, “Vircom Log system” ) )
{
ReportEvent( hEventSource, wEventType, NULL, NULL, NULL, 1, 0, &szMessage, NULL );
DeregisterEventSource( hEventSource );
}
} // void SystemLog

Leave a Reply

Your email address will not be published. Required fields are marked *