Skip to content

Examples WindowsEventLogBackend

Eduard Mishkurov edited this page Jun 3, 2026 · 1 revision

WindowsEventLogBackend example

WindowsEventLogBackend

This Windows-only example writes logme records to Windows Event Log.

The example creates a separate channel, attaches WindowsEventLogBackend, sets the event source, event id, category, and enables asynchronous delivery. It is intentionally excluded from non-Windows builds.

The example target links ws2_32 together with logme, matching other Windows examples in this tree.

Console output

No console output was captured.

Source code

Sources

Repository folder: examples/WindowsEventLogBackend

WindowsEventLogBackend.cpp

Open in repository

#include <Logme/Logme.h>
#include <Logme/Backend/WindowsEventLogBackend.h>
#include <Logme/Channel.h>

#include <memory>

int main()
{
  Logme::ID id{"eventlog"};
  auto channel = Logme::Instance->CreateChannel(id);

  auto config = std::make_shared<Logme::WindowsEventLogBackendConfig>();
  config->Source = "LogmeExample";
  config->EventId = 1000;
  config->Category = 0;
  config->Async = true;

  auto backend = std::make_shared<Logme::WindowsEventLogBackend>(channel);
  backend->ApplyConfig(config);
  channel->AddBackend(backend);

  LogmeI(channel, "Windows Event Log information record");
  LogmeW(channel, "Windows Event Log warning record");
  LogmeE(channel, "Windows Event Log error record");

  backend->Flush();

  return 0;
}

Previous: TypicalUsage examples

Clone this wiki locally