Skip to content

Getting Started

thushxr edited this page Jun 27, 2026 · 1 revision

Getting Started

Requirements

Your project must target .NET 8.0 or later. The package ships native assemblies for .NET 8, .NET 9, and .NET 10; NuGet automatically picks the one matching your <TargetFramework>.

There are no other dependencies — only the .NET base class library.

Install

dotnet add package Thushar.Logging

Or via the Package Manager Console:

Install-Package Thushar.Logging

Or add it to your .csproj directly:

<ItemGroup>
  <PackageReference Include="Thushar.Logging" Version="11.0.0" />
</ItemGroup>

Your first log line

using Thushar.Logging;

Log.Information("Application started");
2026-06-27 09:14:02.318 🟩 [INFO] Application started

That's it — no configuration, no DI, no setup. The logger has sensible defaults (text output, minimum level Information, UTC timestamps) and works the moment you call it.

A namespace tip

The logger types live in the Thushar.Logging namespace, so you normally need:

using Thushar.Logging;

The exception is when your own code is in a child namespace of Thushar.Logging (e.g. Thushar.Logging.Samples.Lambda) — then the types are already in scope through the namespace hierarchy and no using is required. See the FAQ for the details.

Add a little configuration (optional)

Configure once at application startup. It's safe to call again to reconfigure.

using Thushar.Logging;

Log.Configure(o => o
    .UseStructured()                  // JSON instead of text
    .SetMinimumLevel(LogLevel.Debug));

Log.Debug("Cache miss for {key}", "user:42");
{"timestamp":"2026-06-27 09:14:02.401","level":"Debug","icon":"🟦","message":"Cache miss for user:42","key":"user:42"}

See Configuration for the full set of options.

Add class/method context

When you want to know where a line came from, use the typed logger Log<T>:

public class OrderService
{
    public void Process()
    {
        Log<OrderService>.Information("Processing started");
        // text: 2026-… 🟩 [INFO] [OrderService.Process] Processing started
    }
}

Log<T> and the non-generic Log behave differently on purpose — read Log vs Log<T> next so the difference doesn't surprise you.

Where to go from here

Clone this wiki locally