Code // EventLogging. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include <windows. h>
# Include <evntprov. h> // ETW Publishing header
# Include <winevt. h> // EventLog Header.
# Include "Manifest \ manifest. h"
Int _ tmain (int argc, _ TCHAR * argv [])
{
// First step-register the event
REGHANDLE hPub = NULL;
ULONG res = EventRegister (& DOTNETPERFORMANCE_TECHNICALWRITING_PUBLISHER, NULL, NULL, & hPub );
If (ERROR_SUCCESS! = Res ){
_ Tprintf (_ T ("cocould not register event \ n "));
}
Else {
_ Tprintf (_ T ("Event registered successfully \ n "));
}
EVENT_DATA_DESCRIPTOR opEventDesc;
PWSTR pwsOp = L "My Operational Event ";
EventDataDescCreate (& opEventDesc, pwsOp, (ULONG) wcslen (pwsOp) + 1) * sizeof (WCHAR ));
Res = EventWrite (hPub, & DNP_OP_EVENT, 1, & opEventDesc );
If (ERROR_SUCCESS! = Res ){
_ Tprintf (_ T ("cocould not raise operational event Error = % I \ n"), res );
}
Else {
_ Tprintf (_ T ("Operational event successfully raised \ n "));
}
EVENT_DATA_DESCRIPTOR debugEventDesc;
PWSTR pwsDebug = L "My Debug Event ";
EventDataDescCreate (& debugEventDesc, pwsDebug, (ULONG) wcslen (pwsDebug) + 1) * sizeof (WCHAR ));
Res = EventWrite (hPub, & DNP_DEBUG_EVENT, 1, & debugEventDesc );
If (ERROR_SUCCESS! = Res ){
_ Tprintf (_ T ("cocould not raise debug event. Error = % I \ n"), res );
}
Else {
_ Tprintf (_ T ("Debug event successfully raised \ n "));
}
EventUnregister (hPub );
Return 0;
}