An event log utility for Windows 10 & Server 2012/2016 that actually works
npm install node-eventlognode-eventlog is a lightweight C++ based module for Node.js, exclusive for the Windows operating systems, that provides functionality for writing entries to the Event Logs.
batch
npm i node-eventlog
`
However, if there is an issue installing the pre-compiled binaries (such as being behind a corporate firewall), it will fallback to compiling from the source, which means you need to have windows-build-tools or Visual Studio & Python installed.
$3
Something I love about TypeScript is that my definitions file tells you everything you really need to know:
`typescript
export type Severity = "info" | "warn" | "error";
export declare class EventLog {
public readonly source: string;
constructor(source: string);
log(message: string, severity?: Severity, code?: number): Promise;
}
`
Simply import the class, and create a new instance. The constructor requires a source, which is the name of the application that will be displayed in the Event Log entry.
The .log() method will write a new entry to the _Application_ logs. You can optionally provide the type of log entry to write (_info [default], warn, error_), as well as an event code (_default is 1000_).
> _Note_: the .log() method is _Asynchronous_
`javascript
const { EventLog } = require(‘node-eventlog’);
const AppName = ‘MyTestApp’;
const Test = async () => {
const logger = new EventLog(AppName);
console.log(await logger.log(‘Test Message’, ‘info’, 9999));
};
Test();
``