Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log to event viewer on Windows with C++ [closed]

I want to use log on my C++ application. However, I'd like to use Windows (10) event viewer, instead of text files. I found out some weird calls, that I don't even know what the parameters mean - ReportEvent, OpenEventLog and some other Event Logging functions. I also can't use managed code, due to some limitations on my app.

I've also tried to use the code on this link, but I get compilation errors (namespace 'System' undefined - it seems some include files are missing...).

I found no sample code that works yet.

I would appreciate a sample code, if possible - just a simple logging from a local application, built in non managed C++. Can someone help?

like image 632
Leonardo Alves Machado Avatar asked May 04 '16 19:05

Leonardo Alves Machado


People also ask

What is the handle to an object was closed?

Event Description:This event generates when the handle to an object is closed. The object could be a file system, kernel, or registry object, or a file system object on removable storage or a device. This event generates only if Success auditing is enabled for Audit Handle Manipulation subcategory.

How can I see shutdowns in Event Viewer?

1) View Shutdown and Restart Log from Event ViewerType “eventvwr. msc” (no quotes) and hit Enter. The Event Viewer windows will open. After that, navigate to Windows Logs > System on the left pane.


1 Answers

Your link doesn't compile because that's managed C++ (note the use of gcnew)

If all you want to write are strings it's easy, all you need is RegisterEventSource and ReportEvent.

It's approximately this:

const char* custom_log_name = "MyLogName";

// create registry keys for ACLing described on MSDN: http://msdn2.microsoft.com/en-us/library/aa363648.aspx

HANDLE event_log = RegisterEventSource(NULL, custom_log_name);
const char* message = "I'm in an event log";
ReportEvent(event_log, EVENTLOG_SUCCESS, 0, 0, NULL, 1, 0, &message, NULL);

This only allows for logging strings. Much more complex (and useful) logging is possible, but it's fairly involved in straight C++. If you can write managed code for your logging component it becomes easier to deal with.

like image 154
Donnie Avatar answered Sep 27 '22 16:09

Donnie