-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Configure the logger once at startup with Log.Configure(...). It's safe to call again to
reconfigure — each call builds a fresh options object and swaps it in atomically.
Log.Configure(o => o
.UseStructured()
.SetMinimumLevel(LogLevel.Debug)
.AddTraceId());If you never call Configure, the logger runs with the defaults below.
| Fluent method | Property | Default | Effect |
|---|---|---|---|
UseStructured(bool) |
Structured |
false (text) |
JSON output when true, human-readable text when false
|
SetMinimumLevel(LogLevel) |
MinimumLevel |
Information |
Entries below this level are dropped |
UseUtc(bool) |
UseUtcTimestamp |
true |
UTC timestamps when true, local time when false
|
| — | TimestampFormat |
yyyy-MM-dd HH:mm:ss.fff |
Format string for the timestamp |
AddTimestamp(bool) |
IncludeTimestamp |
true |
Render the timestamp field |
AddLevel(bool) |
IncludeLevel |
true |
Render the [LEVEL] field |
AddColorIcon(bool) |
IncludeColorIcon |
true |
Render the color box icon |
AddTraceId(bool) |
IncludeTraceId |
true |
Render the trace-scope id (only shown when one is set) |
UseClassName(bool) |
IncludeClassName |
true |
Render the class field — Log<T> only
|
UseMethodName(bool) |
IncludeMethodName |
true |
Render the method field — Log<T> only
|
Every toggle defaults to on and applies to both text and JSON output. Pass false to
turn a field off:
Log.Configure(o => o.AddColorIcon(false).AddTimestamp(false));
// [INFO] Application startedLog.Configure(o => o.UseStructured(false)); // or just don't call UseStructured
Log.Information("Server listening on {port}", 8080);2026-06-27 09:14:02.318 🟩 [INFO] Server listening on 8080
Field order in text mode: timestamp · icon · [LEVEL] · [TraceId: …] ·
[class.method] · message · (exception on the next line).
Log.Configure(o => o.UseStructured());
Log.Information("Server listening on {port}", 8080);{"timestamp":"2026-06-27 09:14:02.318","level":"Information","icon":"🟩","message":"Server listening on 8080","port":8080}Field order in JSON mode: timestamp · level · icon · traceId · class · method ·
message · (your template fields) · exception.
To change just the minimum level without a full reconfigure:
Log.MinimumLevel = LogLevel.Warning; // get or set directlyThis is handy for toggling verbosity on the fly (e.g. from an admin endpoint or env var).
-
UTC vs local:
UseUtc()(default) usesDateTime.UtcNow;UseUtc(false)usesDateTime.Now. For server/cloud logging, UTC is strongly recommended. -
Format: set
TimestampFormatto any standard or custom .NET date format string. It's applied withCultureInfo.InvariantCulturefor stable, locale-independent output.Log.Configure(o => { }); // defaults // To customize the format, set the property inside Configure: Log.Configure(o => o.UseStructured()); // (TimestampFormat is a settable property on the options object)
UseClassName / UseMethodName control fields that only the typed Log<T> produces. The
non-generic Log never captures a class or method, so toggling these has no effect on it. See
Log vs Log<T> for the full explanation.
| Level | Icon |
|---|---|
| Trace | ⬜ |
| Debug | 🟦 |
| Information | 🟩 |
| Warning | 🟨 |
| Error | 🟥 |
| Critical | 🟪 |
The icon is rendered to the left of the level in text mode, and as the icon field in JSON.
Turn it off with AddColorIcon(false) if your sink doesn't render emoji well.
Thushar.Logging · a zero-dependency static logger for .NET
📦 NuGet · 💻 GitHub · 🐛 Issues · 📸 Instagram
dotnet add package Thushar.Logging
Getting around
Features
Using it
Under the hood