EasyLogWriter 1.2.0
dotnet add package EasyLogWriter --version 1.2.0
NuGet\Install-Package EasyLogWriter -Version 1.2.0
<PackageReference Include="EasyLogWriter" Version="1.2.0" />
<PackageVersion Include="EasyLogWriter" Version="1.2.0" />
<PackageReference Include="EasyLogWriter" />
paket add EasyLogWriter --version 1.2.0
#r "nuget: EasyLogWriter, 1.2.0"
#:package EasyLogWriter@1.2.0
#addin nuget:?package=EasyLogWriter&version=1.2.0
#tool nuget:?package=EasyLogWriter&version=1.2.0
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.
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
New in v1.1 — structured, scoped & production-ready:
- 🖥️ Multiple targets / sinks —
LogTarget.File | LogTarget.Console(colored console output) - 🗂️ Separate files by level —
info-2026-08-04.log,error-2026-08-04.log - 🧾 JSON sidecar — write a parallel
.jsonfile alongside text for ELK/Grafana - 🔗 Correlation / request id — trace one operation across many methods
- ⏱️ Execution-time logging —
using (Logger.Measure("LoadDashboard")) { ... } - 🏷️ Scoped logging —
using (Logger.BeginScope("StudentImport")) { ... } - 🔄 Flexible rolling — Daily, Hourly, and size-based rotation
- 🗜️ Archive & compress — old logs zipped to
.zip, then deleted after retention - 🙈 Sensitive-data masking — hide
Password,Token, emails, and custom fields
New in v1.2 — extensible & framework-friendly:
- 🔌 Custom sink API — implement
ILogSinkfor SQL, MongoDB, Elasticsearch, HTTP, … - 🧩 Enrichers — auto-add
MachineName,AppVersion,Environment,ProcessId,ThreadId - 📊 Runtime diagnostics —
Logger.Diagnostics(written / queued / failed / dropped) - 🧵
Microsoft.Extensions.Loggingintegration —ILogger/ILoggerProvider+ DI via the companion packageEasyLogWriter.Extensions.Logging
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. |
Targets |
File |
Output destinations: File, Console, or both (File \| Console). |
Rolling |
Daily |
Time-based rolling: Daily, Hourly, or Infinite. |
SeparateFilesByLevel |
false |
Write each level to its own file (info-…, error-…). |
AlsoWriteJson |
false |
Also write a parallel .json file (when Format = Text). |
ConsoleUseColors |
true |
Color console output by level. |
EnableArchive |
false |
Compress old files to .zip on startup. |
ArchiveAfterDays |
7 |
Age after which a file is archived. |
MaskFields |
[] |
Property names to fully mask, e.g. { "Password", "Token" }. |
MaskEmails |
false |
Partially mask email-looking property values. |
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.DispatcherUnhandledExceptionand callLogger.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();
v1.1 features
Multiple targets (File + Console)
Logger.Init(new LoggerOptions
{
AppName = "MyApp",
Targets = LogTarget.File | LogTarget.Console, // colored console + file
});
Separate files by level
Logger.Init(new LoggerOptions { AppName = "MyApp", SeparateFilesByLevel = true });
logs/
├── info-2026-08-04.log
├── warning-2026-08-04.log
└── error-2026-08-04.log
JSON alongside text
Logger.Init(new LoggerOptions { AppName = "MyApp", AlsoWriteJson = true });
// -> MyApp-2026-08-04.log (text) + MyApp-2026-08-04.json (JSON Lines)
Correlation / request id
Logger.CorrelationId = "ORDER-A7F21";
Logger.Info("Payment received"); // every entry now carries ORDER-A7F21
Logger.Info("Invoice generated");
Logger.CorrelationId = null; // clear when the operation ends
The id flows across async/await, so one operation is traceable end-to-end.
Scoped logging
using (Logger.BeginScope("StudentImport"))
{
Logger.Info("started"); // tagged [StudentImport]
using (Logger.BeginScope("Validate"))
{
Logger.Warning("bad row"); // tagged [StudentImport/Validate]
}
}
Execution-time logging
using (Logger.Measure("LoadDashboard"))
{
LoadDashboard();
}
// -> LoadDashboard completed in 428 ms
Flexible rolling & archiving
Logger.Init(new LoggerOptions
{
AppName = "MyApp",
Rolling = RollingInterval.Hourly, // Daily | Hourly | Infinite
MaxFileSizeMB = 20, // + size-based rotation
EnableArchive = true, // zip files older than…
ArchiveAfterDays = 7, // …7 days
KeepLogsForDays = 30, // then delete after 30
});
Sensitive-data masking
Logger.Init(new LoggerOptions
{
AppName = "MyApp",
MaskFields = new List<string> { "Password", "Token", "ApiKey" },
MaskEmails = true,
});
Logger.Info("User signup", new { Email = "nilesh@gmail.com", Password = "s3cr3t" });
// -> {Email=ni****@gmail.com, Password=********}
v1.2 features
Custom sinks
Write logs anywhere — a database, a queue, a remote API — by implementing ILogSink:
using EasyLogWriter;
using EasyLogWriter.Sinks;
public class SqlSink : ILogSink
{
public void Emit(LogEntry entry) { /* INSERT INTO Logs ... */ }
public void Dispose() { }
}
Logger.Init(new LoggerOptions { AppName = "MyApp" }.AddSink(new SqlSink()));
A sink that throws does not break logging — the failure is counted in
Logger.Diagnostics.Failed.
Enrichers
Automatically attach ambient properties to every entry:
var options = new LoggerOptions { AppName = "MyApp" };
options.Enrichers.AddRange(Enrichers.Common()); // MachineName, AppVersion, Environment, ProcessId, ThreadId
options.EnrichWith(new PropertyEnricher("Region", "IN"));
Logger.Init(options);
Built-in: MachineNameEnricher, AppVersionEnricher, EnvironmentEnricher,
ProcessIdEnricher, ThreadIdEnricher, PropertyEnricher. Implement ILogEnricher
for your own.
Runtime diagnostics
var stats = Logger.Diagnostics;
// stats.Written, stats.Queued, stats.Failed, stats.Dropped
Console.WriteLine(stats); // Written=1024, Queued=3, Failed=0, Dropped=0
ASP.NET Core / dependency injection
Install the companion package:
dotnet add package EasyLogWriter.Extensions.Logging
Plug EasyLogWriter into the standard Microsoft logging pipeline:
using EasyLogWriter;
using EasyLogWriter.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddEasyLogWriter(o =>
{
o.AppName = "MyApi";
o.Targets = LogTarget.File | LogTarget.Console;
o.Enrichers.AddRange(Enrichers.Common());
});
Now inject ILogger<T> anywhere as usual — it writes through EasyLogWriter. The
logger category is recorded as the SourceContext property, and
ILogger.BeginScope(...) maps to EasyLogWriter scopes.
Tip: when you use both
EasyLogWriterandMicrosoft.Extensions.Loggingnamespaces,LogLevelis ambiguous — fully qualify one, e.g.Microsoft.Extensions.Logging.LogLevel.Debug.
Packages
| Package | Purpose | Dependencies |
|---|---|---|
EasyLogWriter |
Core logging (files, console, sinks, enrichers, …) | None |
EasyLogWriter.Extensions.Logging |
ILogger / ILoggerProvider + DI |
Microsoft.Extensions.Logging.Abstractions |
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 | Versions 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. |
-
.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.
v1.2.0 — Extensibility foundation (backward compatible). Adds: public custom sink API (ILogSink) for SQL/Mongo/HTTP/etc., log enrichers (MachineName, AppVersion, Environment, ProcessId, ThreadId), runtime diagnostics counters (Logger.Diagnostics), and a Logger.Log(level, ...) bridge method. Companion package EasyLogWriter.Extensions.Logging adds Microsoft.Extensions.Logging (ILogger/ILoggerProvider) and DI support.