///////////////////////////////////////////////////////////////////////////////
// copyright (c) Winnov L.P., 1997.  All rights reserved
// log.cpp: log manager
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include "log.h"
#include "debug.h"

DWORD gsnLogCount = 0;
#define MAX_LOG_COUNT	5

void LogEvent (DWORD dwStatus, LPCTSTR tzMsg)
{
    HANDLE  hEventSource;
    LPCTSTR  lpszStrings [3];
    BOOL fResult;
    TCHAR buf [256];

    wsprintf (buf, L"\nStatus=%ld", dwStatus);

    TraceString ("\nLogEvent: ");
    TraceWString ((LPTSTR)tzMsg);
    TraceWString (buf);

    if (gsnLogCount > MAX_LOG_COUNT)
	return;

    gsnLogCount++;

    hEventSource = RegisterEventSource (NULL, TEXT("WnvIrq32.exe"));
    if (!hEventSource) 
    {
	TraceString ("\n********** LogEvent: RegisterEventSource failed.");
	return;
    }

    lpszStrings[0] = tzMsg;
    lpszStrings[1] = buf;
    lpszStrings[2] = NULL;

    fResult = ReportEvent(
	hEventSource, // handle of event source
        EVENTLOG_ERROR_TYPE,  // event type
        0,                    // event category
        0,                    // event ID
        NULL,                 // current user's SID
        2,                    // strings in lpszStrings
        0,                    // no bytes of raw data
        lpszStrings,	      // array of error strings
        NULL);                // no raw data
    if (!fResult)
    {
	TraceString ("\n********** LogEvent: ReportEvent failed.");
	return;
    }

    DeregisterEventSource (hEventSource);
}
