you need
  • - compiler C;
  • - Windows Platform SDK;
  • - Develop-package glibc.
Add support for logging to the system log of your applications designed to run on operating systems Windows.

Use API functions RegisterEventSource application for registration as a source of events ReportEvent function to add an entry in the log and DeregisterEventSource function to close the handle returned RegisterEventSource.

Call RegisterEventSource makes sense to produce in the process of initializing the application and save it returned handle all the work so that from different areas of the program could produce a publication record in the log.The simplest example of a log entry in Windows may look like this:

HANDLE hLog = RegisterEventSource (NULL, "MyApplicationName");

if (hLog! = NULL)
if (ReportEvent (hLog, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL,
1, 0, "Message text \ 0", NULL))
// event successfully placed inlog

DeregisterEventSource (hLog);

For more information on the semantics of the function ReportEvent can be found in the MSDN link addition, it is necessary to place some data on an executable program modules in the system registry, and the module itself or a third-party add dynamic library resources in a specific format.For more information about the registry keys for the event log service can be found on the page
Write logs into a Linux-compatible operating systems, you can usually using daemon syslog.This service has an interface application layer as a set of functions, which are placed in the declaration header file syslog.h.

Use the openlog to create a connection to the syslog of the application or library.Call the syslog or vsyslog to post messages in the log.After recording the event or at the conclusion of the application, close the connection to the service by calling closelog.In addition, you can configure to ignore the call, adding event records with a certain priority by using the tool setlogmask.Example entries in the log messages can look like this:

openlog ("MyApplication", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog (LOG_NOTICE, "MyApplication is launched with PID% d", getuid ());
syslog (LOG_INFO, "Information message!");
closelog ();

More detailed information about the parameters of function application programming interface syslog can be found in the info-documentation for libc.
Write logs into arbitrary files, using its own data logging subsystem.One of the simplest solutions to this problem is to create several functions in the global scope, one of which opens a file with a particular name in the mode of adding the information, the second - close it, and the third - adds the file message string passed as a parameter.Conceptually, this decision resembles a programming interface syslog on Linux.

Use the fopen and fclose standard C library to open and close the file, respectively.Call fwrite to add information to a file.You can also use the platform-spetsifichekie function (for example, CreateFile under Windows) objects and methods used by frameworks that encapsulate functionality to work with files.