Link to home
Start Free TrialLog in
Avatar of pwang1973
pwang1973

asked on

VC++ write Event Log

Does anybody know the API, sample code to write msg to the 2000's event log since I am debugging an .EXE invoked from the ASP.

THanks
Pat
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunwell
sunwell

you can do in another way that I used to do.
you can download a debugview form www.sysinternals.com, it is a free ware.
then in your program:

TCHAR myBuffer[1024];
..........
_stprintf( myBuffer, _T(" if it is printed, something happened. %u"), uintValue);
::OutputDebugString( myBuffer);
( TRACE macro called this api OutputDebugString too)
then in your release / debug run, you can see the output message in the debugView.
it is a very good tool.


Create a function to write info to the log:

void CTest1Dlg::LogEvent(const TCHAR* psz, bool bError)
{
   const TCHAR* rgsz[] = { psz };

   HANDLE hes = RegisterEventSource(0, "My event source");
   if(hes)
   {
      WORD dwEventType = bError ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE;
        DWORD dwEventID = bError ? (DWORD)0xE0000001L : (DWORD)0x20000001L;
      ReportEvent(hes, dwEventType, 0, dwEventID, 0, 1, 0, rgsz, 0);
      DeregisterEventSource(hes);
   }
}

and call that function:

      LogEvent("test", true);      
      LogEvent("test", false);      


HTH,

Jack