Crates.io | eventlog |
lib.rs | eventlog |
version | 0.3.0 |
source | src |
created_at | 2020-06-25 13:44:57.067267 |
updated_at | 2024-10-25 23:55:28.211682 |
description | A log-compatible wrapper around the Windows Event Log API |
homepage | |
repository | https://github.com/bbqsrc/eventlog |
max_upload_size | |
id | 257863 |
size | 34,317 |
A log-compatible wrapper around the Windows Event Log API.
Thanks to Jeroen C. van Gelderen for creating the winlog project from which this is forked.
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 |
eventmsgs.mc
is changed)[dependencies]
eventlog = "0.1.0"
Register the log source in the Windows registry:
eventlog::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.
eventlog::init("Example Log", log::Level::Trace).unwrap();
info!("Hello, Event Log");
trace!("This will be logged too");
Deregister the log source:
eventlog::deregister("Example Log").unwrap();
This is usually done during program uninstallation. If your MSI installer (or similar) deregisters your event sources you should not call this.
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.
If build.rs
determines that eventmsgs.mc
was changed then build.rs
:
mc.exe
(which creates eventmsgs.h
)rc.exe
(which creates eventmsgs.lib
)eventmsgs.rs
from eventmsgs.h
.build.rs
emits linker flags so eventmsgs.lib
can found.
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
Create a unique temporary event source name (eventlog-test-###########
).
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\eventlog-test-###########
.
Write some log messages to the event source.
Use PowerShell to retrieve the logged messages.
Deregister our event source. This removes the eventlog-test-###########
registry key.
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.