Unit test module that writes to windows event viewer by writing to a file

Ritu Varkey 41 Reputation points
2021-07-16T05:27:27.42+00:00

I want to unit test my code that writes to windows event log. I use the ReportEvent function. Is there a way to make the function write to a file instead of windows eventviewer? I tried providing a file handle as the first parameter but it returned with invalid handle error. How can I test my code?

int res = ReportEvent( pfile, EVENTLOG_INFORMATION_TYPE, 0, 256, NULL, static_cast<WORD>(eventDetails.size()), 0, &eventDetails[0], NULL );

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,617 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,729 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2021-07-16T08:26:01.54+00:00

    The RegisterEventSource function returns the hEventLog of ReportEvent .
    And According to The Eventlog Key Topic, You can Custom the File registry value Which specifies Fully qualified path to the file where each event log is stored in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\YourEventProvider registry key.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.