EasyLogWriter 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyLogWriter --version 1.0.0
                    
NuGet\Install-Package EasyLogWriter -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="EasyLogWriter" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyLogWriter" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EasyLogWriter" />
                    
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 EasyLogWriter --version 1.0.0
                    
#r "nuget: EasyLogWriter, 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 EasyLogWriter@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=EasyLogWriter&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EasyLogWriter&version=1.0.0
                    
Install as a Cake Tool

EasyLogWriter

Simple, lightweight, and developer-friendly logging library for .NET applications.

EasyLogWriter gives you production-grade file logging with a one-line setup — no configuration files, no boilerplate. It is async, thread-safe, and works everywhere: WPF, WinForms, Console, ASP.NET, and any .NET Standard 2.0+ target.

NuGet


Features

  • ✅ One-line setup — Logger.Init("MyApp");
  • ✅ Log levels — Debug, Info, Warning, Error, Critical
  • ✅ Daily log files — logs/MyApp-2026-08-04.log
  • ✅ Automatic folder creation — no need to create directories yourself
  • ✅ Exception logging — message + stack trace + inner exceptions captured automatically
  • ✅ File rotation — starts a new file when size limit (default 10 MB) is reached
  • ✅ Old-log auto cleanup — KeepLogsForDays = 30
  • ✅ Thread-safe — many threads can log at once without corruption
  • ✅ Async logging — the UI thread is never blocked (great for WPF)
  • ✅ Custom properties / context — attach structured data to any entry
  • ✅ Text or JSON output — human-readable or machine-parseable
  • ✅ Caller info — method, file, and line captured automatically
  • ✅ Global unhandled-exception logging — crashes are logged before the app dies
  • ✅ Configurable log path & minimum level
  • ⭐ Session-based logging — every run gets a unique SessionId, attached to every line

Installation

dotnet add package EasyLogWriter

Or via the Package Manager Console:

Install-Package EasyLogWriter

Quick start

using EasyLogWriter;

// One line — that's the whole setup.
Logger.Init("MyApp");

Logger.Info("Application started");
Logger.Warning("Internet connection is slow");
Logger.Error("Unable to save file");

// Log an exception with full detail.
try
{
    SaveStudent();
}
catch (Exception ex)
{
    Logger.Error(ex, "Database operation failed");
}

This creates logs/MyApp-2026-08-04.log next to your executable:

==================================================
Session:     8F42A1
App Version: 2.5.1
OS:          Microsoft Windows 10.0.22631
Machine:     DESKTOP-123
Started:     2026-08-04 12:30:10
==================================================
2026-08-04 12:30:15 | 8F42A1 | INFO     | Application started | Program.Main() Line: 12
2026-08-04 12:30:16 | 8F42A1 | WARNING  | Internet connection is slow | Program.Main() Line: 13
2026-08-04 12:30:17 | 8F42A1 | ERROR    | Unable to save file | Program.Main() Line: 14

Configuration

For full control, pass a LoggerOptions:

Logger.Init(new LoggerOptions
{
    AppName          = "MyApp",
    LogDirectory     = @"C:\MyApp\Logs",   // absolute or relative to the app folder
    MinimumLevel     = LogLevel.Warning,   // ignore Debug/Info in production
    Format           = LogFormat.Json,     // Text (default) or Json
    MaxFileSizeMB    = 10,                  // rotate at 10 MB
    KeepLogsForDays  = 30,                  // delete logs older than 30 days
    Async            = true,                // never block the calling thread
});

Options

Option Default Description
AppName "App" Prefix for log file names.
LogDirectory "logs" Where logs are written (created automatically). Relative paths resolve against the app base directory.
MinimumLevel Debug Entries below this level are ignored.
Format Text Text or Json.
MaxFileSizeMB / MaxFileSizeBytes 10 MB Rotate to a new file when exceeded. Set MaxFileSizeBytes = 0 to disable.
KeepLogsForDays 30 Delete older files on startup. 0 = keep forever.
CaptureCallerInfo true Capture method / file / line of the caller.
Async true Queue writes on a background thread.
CaptureUnhandledExceptions true Log unhandled & unobserved-task exceptions.
WriteSessionHeader true Write the session header block at the top of each file.

Log levels

Logger.Debug("Detailed diagnostic info");
Logger.Info("Normal application flow");
Logger.Warning("Something unexpected, but recoverable");
Logger.Error("An operation failed");
Logger.Critical("The application cannot continue");

Filter with MinimumLevel so Debug/Info files don't grow unnecessarily in production:

Logger.Init(new LoggerOptions { AppName = "MyApp", MinimumLevel = LogLevel.Warning });

Custom properties / context

Attach structured data to any entry with an anonymous object:

Logger.Info("User logged in", new { UserId = 101, Machine = "PC-01" });

Text output:

2026-08-04 12:30:15 | 8F42A1 | INFO     | User logged in | AuthService.Login() Line: 42 | {UserId=101, Machine=PC-01}

JSON output (Format = LogFormat.Json):

{"timestamp":"2026-08-04T12:30:15","level":"Info","sessionId":"8F42A1","message":"User logged in","caller":"AuthService.Login() Line: 42","properties":{"UserId":101,"Machine":"PC-01"}}

JSON output is written as JSON Lines — one compact JSON object per line — which is what log processors (Elastic, Seq, Loki, etc.) expect.


Exception logging

Logger.Error(ex, "Failed to save student");

The message, exception type, stack trace, and every inner exception are captured automatically:

2026-08-04 12:32:14 | 8F42A1 | ERROR    | Failed to save student | StudentService.Save() Line: 82
    Exception: System.ApplicationException: Database connection failed
       at StudentService.Save() ...
    Inner Exception: System.InvalidOperationException: Timeout expired
       at ...

Session-based logging ⭐

Every call to Logger.Init starts a new session with a unique short id. That id is written into a header at the top of the file and attached to every line, so all logs from one run are trivially correlated — a huge help for support and debugging.

Logger.Init("MyApp");
var id = Logger.Session!.SessionId;   // e.g. "8F42A1"
12:30:15 | 8F42A1 | INFO     | Application Started
12:31:02 | 8F42A1 | INFO     | Login successful
12:32:14 | 8F42A1 | ERROR    | Database connection failed

Global unhandled-exception logging

By default EasyLogWriter installs handlers for AppDomain.UnhandledException and TaskScheduler.UnobservedTaskException, so even an unexpected crash is recorded before the process exits. Disable with CaptureUnhandledExceptions = false.

WPF tip: also hook Application.DispatcherUnhandledException and call Logger.Error(e.Exception, "Dispatcher exception"); to catch UI-thread exceptions.


Shutdown

When using async logging, call Logger.Shutdown() on exit to flush any queued entries to disk:

Logger.Shutdown();

Requirements

  • .NET Standard 2.0+ (works with .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5/6/7/8/9)
  • No external dependencies.

License

MIT © Nilesh Chaudhari

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.

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.2.0 154 8/4/2026
1.1.0 127 8/4/2026
1.0.0 131 8/4/2026