#logging #windows #eventlog


A simple Rust log backend to send messages to the Windows event log

4 releases

0.2.1 Oct 5, 2018
0.2.0 Oct 2, 2018
0.1.1 Oct 1, 2018
0.1.0 Sep 29, 2018

#76 in Debugging

Download history 2/week @ 2018-10-26 26/week @ 2018-11-02 19/week @ 2018-11-09 8/week @ 2018-11-16 7/week @ 2018-11-23 32/week @ 2018-11-30 44/week @ 2018-12-07 56/week @ 2018-12-14 13/week @ 2018-12-21 63/week @ 2018-12-28 9/week @ 2019-01-04 28/week @ 2019-01-11 24/week @ 2019-01-18

108 downloads per month


209 lines


Latest version License

A simple Rust log backend to send messages to the Windows event log.

  • Writes Rust log messages to the Windows event log using the RegisterEventSourceW and ReportEventW APIs.
  • Provides utility functions to register/unregister your event source in the Windows registry.
  • Embeds a small (120-byte) message resource library containing the necessary log message templates in your executable.
  • Does not panic.

The five Rust log levels are mapped to Windows event types as follows:

Rust Log Level Windows Event Type Windows Event Id
Error Error 1
Warn Warning 2
Info Informational 3
Debug Informational 4
Trace Informational 5


  • Rust stable (tested on 1.29)
  • Windows
  • (optional) PowerShell (used for the end-to-end test)
  • (optional) mc.exe and rc.exe (only required when eventmsgs.mc is changed)


Add to cargo.toml:

winlog = "*"

Register the log source in the Windows registry:

winlog::register("Example Log"); // silently ignores errors
// or
winlog::try_register("Example Log").unwrap();

This usually requires Administrator permission so this is usually done during installation time. If your MSI installer (or similar) registers your event sources you should not call this.

Use the winlog backend:

winlog::init("Example Log").unwrap();
info!("Hello, Event Log");

Deregister the log source:

winlog::deregister("Example Log"); // silently ignores errors
// or
winlog::try_deregister("Example Log").unwrap();

This is usually done during program uninstall. If your MSI installer (or similar) deregisters your event sources you should not call this.


cargo build --release


Artifacts eventmsgs.lib and eventmsgs.rs are under source control so users don't need to have mc.exe and rc.exe installed for a standard build.

  1. If build.rs determines that eventmsgs.mc was changed then build.rs:
    • invokes mc.exe (which creates eventmsgs.h)
    • invokes rc.exe (which creates eventmsgs.lib)
    • creates eventmsgs.rs from eventmsgs.h.
  2. build.rs emits linker flags so eventmsgs.lib can found.
  3. Standard cargo build follows.


The end-to-end test requires 'Full Control' permissions on the HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application registry key.

cargo test


  1. Create a unique temporary event source name (winlog-test-###########).
  2. Register our compiled test executable as EventMessageFile for the event source in the Windows registry. You can see a new key at HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\winlog-test-###########.
  3. Write some log messages to the event source.
  4. Use PowerShell to retrieve the logged messages.
  5. Deregister our event source. This removes the winlog-test-########### registry key.
  6. Assert that the retrieved log messages are correct.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.



  • build build.rs
  • build regex 1.0
  • dev rand 0.5