EventLogApi 1.0.0

There is a newer version of this package available.
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" />
                    
Directory.Packages.props
<PackageReference Include="EventLogApi" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=EventLogApi&version=1.0.0
                    
Install as a Cake Tool

📝 EventLogApi

NuGet NuGet Downloads

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)
  • 🛡️ 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.


Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 141 9/10/2025
1.0.4 139 9/10/2025
1.0.3 136 9/10/2025
1.0.2 139 9/9/2025
1.0.1 141 9/9/2025
1.0.0 134 9/9/2025