EventLogApi 1.0.6

dotnet add package EventLogApi --version 1.0.6
                    
NuGet\Install-Package EventLogApi -Version 1.0.6
                    
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.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EventLogApi" Version="1.0.6" />
                    
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.6
                    
#r "nuget: EventLogApi, 1.0.6"
                    
#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.6
                    
#: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.6
                    
Install as a Cake Addin
#tool nuget:?package=EventLogApi&version=1.0.6
                    
Install as a Cake Tool

EventLogApi

A modern .NET wrapper for the Windows Event Log.
It allows you to write, read, and watch events in a strongly typed and developer-friendly way.

✨ Features

  • Write events (Information, Warning, Error) with optional structured JSON payload
  • Read events with filtering (by severity, provider, text, time, etc.)
  • Watch events in real-time via EventLogWatcherService
  • Provides a flattened DTO (EventRecordDto) with safe access to all key fields
  • Clear error handling via EventLogApiException

📦 Installation

Install via NuGet:

dotnet add package EventLogApi

Or via the Visual Studio NuGet Package Manager.

🚀 Usage

Write Events

using EventLogApi;

var writeOpts = new WriteOptions
{
    Source = "MyApp",
    LogName = "Application",
    AutoCreateSource = true // requires admin on first run
};

EventLogWriter.Info("Hello World (Information)", writeOpts);
EventLogWriter.Warn("Heads-up (Warning)", writeOpts);
EventLogWriter.Error("Something failed (Error)", writeOpts);

// Write an exception
try
{
    throw new InvalidOperationException("Something broke");
}
catch (Exception ex)
{
    EventLogWriter.WriteException(ex, "Error while processing request", writeOpts);
}

// Write structured payload
EventLogWriter.WriteStructured(
    "User {UserId} performed {Action}",
    new { UserId = 42, Action = "Login" },
    EventSeverity.Information,
    writeOpts);

Read Events

using EventLogApi;

var options = new QueryOptions
{
    LogName = "Application",
    MaxEvents = 20,
    ContainsText = "MyApp",
    NewestFirst = true
};

var events = EventLogReader.Read(options);

foreach (var e in events)
{
    Console.WriteLine($"{e.TimeCreated:u} [{e.LevelDisplayName}] {e.ProviderName} - {e.Message}");
}

Watch Events in Real-Time

using EventLogApi;

using var watcher = new EventLogWatcherService("Application", ".", "*[System/Level=2]"); // errors only

watcher.OnEvent += e =>
{
    Console.WriteLine($"[WATCH] {e.TimeCreated:u} {e.ProviderName}: {e.Message}");
};

watcher.OnError += ex =>
{
    Console.WriteLine($"[WATCH][ERROR] {ex.Message}");
};

watcher.Start();
Console.ReadKey(); // keep alive

📖 API Overview

  • EventLogWriter

    • Info(string message, WriteOptions? opt = null)
    • Warn(string message, WriteOptions? opt = null)
    • Error(string message, WriteOptions? opt = null)
    • WriteException(Exception ex, string? contextMessage = null, WriteOptions? options = null)
    • WriteStructured(string messageTemplate, object payload, EventSeverity severity, WriteOptions? options = null)
  • EventLogReader.Read(QueryOptions options)

    • Reads events with filtering (by time, text, severity, provider, etc.)
  • EventLogWatcherService

    • Watches a log in real-time and raises OnEvent for new entries
  • EventRecordDto

    • Flattened event with Id, Level, ProviderName, TimeCreated, Message, etc.
  • EventLogApiException

    • Clear exception type for all API errors

✅ Supported Platforms

  • Windows 10, Windows 11, Windows Server
  • .NET 6, .NET 7, .NET 8

⚠️ Notes

  • Creating a new source requires Administrator rights on first run
  • Reading certain logs (like Security) requires elevated permissions
  • The API uses System.Diagnostics.EventLog and System.Diagnostics.Eventing.Reader internally

📜 License

MIT License

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 67 9/10/2025
1.0.4 69 9/10/2025
1.0.3 64 9/10/2025
1.0.2 69 9/9/2025
1.0.1 71 9/9/2025
1.0.0 64 9/9/2025