EventLogApi 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EventLogApi --version 1.0.0
NuGet\Install-Package EventLogApi -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EventLogApi" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EventLogApi" Version="1.0.0" />
<PackageReference Include="EventLogApi" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EventLogApi --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EventLogApi, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EventLogApi@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EventLogApi&version=1.0.0
#tool nuget:?package=EventLogApi&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
📝 EventLogApi
A simple, robust Windows Event Log API for .NET.
Provides helpers to write, read, and watch Windows Event Logs with clean, strongly typed APIs.
✨ Features
🔹 Write to Windows Event Log
- Info / Warning / Error helpers
- Structured JSON payloads
- Exception logging with stacktrace
- Auto-create event sources (requires Admin once)
🔹 Read from Windows Event Log
- Query options: time filter, severity, sources, message contains
- Returns clean
EventRecordDto
objects - Supports
Application
,System
,Security
, and custom logs
🔹 Watch Windows Event Logs
- Event-based API using
EventLogWatcher
- Supports XPath filters (e.g., errors only)
- Event-based API using
🛡️ Full error handling (
EventLogApiException
)💻 Windows-only (
net8.0-windows7.0
)
📦 Installation
Install via NuGet:
dotnet add package EventLogApi
Or add to .csproj
:
<PackageReference Include="EventLogApi" Version="1.0.0" />
🚀 Quick Start
Write to Event Log
using EventLogApi;
var opts = new WriteOptions
{
Source = "EventLogApi.Demo",
LogName = "Application",
AutoCreateSource = true // requires admin the first time
};
EventLogWriter.Info("Hello from EventLogApi!", opts);
EventLogWriter.Warn("Heads-up warning!", opts);
EventLogWriter.Error("Something went wrong!", opts);
try
{
throw new InvalidOperationException("Demo exception");
}
catch (Exception ex)
{
EventLogWriter.WriteException(ex, "Caught exception", opts);
}
EventLogWriter.WriteStructured(
"User {UserId} performed {Action}",
new { UserId = 42, Action = "Login" },
EventSeverity.Information,
opts);
Read from Event Log
var q = new QueryOptions
{
LogName = "Application",
MaxEvents = 10,
ContainsText = "EventLogApi",
NewestFirst = true
};
var events = EventLogReader.Read(q);
foreach (var e in events)
{
Console.WriteLine($"{e.TimeCreated:u} [{e.LevelDisplayName}] {e.ProviderName} - {e.Message}");
}
Watch Event Log (Errors only)
using var watcher = new EventLogWatcherService("Application", ".", "*[System/Level=2]");
watcher.OnEvent += e =>
{
Console.WriteLine($"[ERROR] {e.TimeCreated:u} {e.ProviderName}: {e.Message}");
};
watcher.OnError += ex =>
{
Console.WriteLine($"Watcher error: {ex.Message}");
};
watcher.Start();
Console.ReadKey(); // keep alive
🖥️ Requirements
- Windows 7 or later
- .NET 6/7/8 (Windows-specific TFM:
net8.0-windows7.0
) - Admin rights may be required for some logs (
Security
, source creation)
📜 License
MIT License – free for commercial and open source use.
🔗 Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0-windows7.0
- System.Diagnostics.EventLog (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.