TinyLogger 3.0.0

dotnet add package TinyLogger --version 3.0.0                
NuGet\Install-Package TinyLogger -Version 3.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="TinyLogger" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TinyLogger --version 3.0.0                
#r "nuget: TinyLogger, 3.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.
// Install TinyLogger as a Cake Addin
#addin nuget:?package=TinyLogger&version=3.0.0

// Install TinyLogger as a Cake Tool
#tool nuget:?package=TinyLogger&version=3.0.0                

TinyLogger

NuGet Build

TinyLogger is a lightweight, extendable logging library for .NET developers. It integrates seamlessly with Microsoft.Extensions.Logging to provide rich console and file logging options, enhanced readability through type-aware color-coded output, and customizable log message formats.

Table of Contents

Key Features

  • Lightweight and extendable
  • Supports console and file logging
  • Customizable log message formats
  • Type-aware color-coded console output
  • Built on Microsoft.Extensions.Logging

Simple example

If builder is an instance of ILoggingBuilder you can simply add the console logger like this:

builder.AddTinyConsoleLogger();

Keep in mind that the if the standard console logger is in use it may have to be disabled as well, check out how to do this in the appsettings.json file of the generic host sample project.

More complex example

For more configuration options and file logging, use AddTinyLogger method instead. Checkout the sample ConsoleApp for a complete example.

builder.AddTinyLogger(options =>
{
    // Add custom data to log fields
    options.Extenders.Add(new SampleExceptionExtender());

    // Use a predefined timestamped message template
    options.Template = MessageTemplates.DefaultTimestamped;

    // Log messages to the console
    options.AddConsole();

    // Log messages to a static file
    options.AddFile("example.log");

    // Log messages to rolling files based on timestamp
    options.AddRollingFile(() => $"example-{DateTime.Now:yyyyMMdd-HHmm}.log");
});

Screenshot of ConsoleApp sample

With TinyLogger

Notice the different colors for numbers, strings, dates, uris, easily readable lists and dictionaries, and so on. Colors are selected based on the underlying data type, even in dictionaries. Screenshot of sample output with TinyLogger

With standard console logger

The standard .NET console logger has no spacing between log messages and no color coding except for log levels which makes it very hard to read. Screenshot of sample output with standard console logger

Benefits and drawbacks

Because it is a logger provider like any other you are free to use other loggers as well, TinyLogger won't get in your way. And since it is built on top of the standard logging abstractions from Microsoft there is no magic other than adding the logging provider and the simple configuration.

How it works

When a log message is received it is passed to an internal message tokenizer which parses the original log format, extracts data from the log message state and creates a list of message tokens which easily can be rendered by any class implementing the ILogRenderer interface.

The console renderer will render tokens containing object values with different colors depending on their type so logs easier to read, while the file logger will render in plain text.

If you want one log format for the console and one log format for files, you can simply add two instances of TinyLogger with different configuration options.

Background workers

Everything is rendered on background threads to be as non blocking as possible.

This however means that messages are temporarily stored on a queue until they are ready to be processed by a log renderer, which should normally be nearly instantly. But if log messages are produced faster than can be rendered then eventually you may hit the configurable queue depth limit.

If this happens a decision has to be made whether to keep all messages in which case logging threads will be blocked until the log renderers can catch up, or start discarding messages to give renderers more breathing room.

It's important to note that the limiting factor here isn't TinyLogger but rather the console itself, it can be pretty slow on Windows particularly. File logging is much, MUCH faster.

The default behavior is to keep all messages.

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 is compatible. 
.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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on TinyLogger:

Repository Stars
steamcore/TinyIpc
.NET inter process broadcast message bus with supporting classes
Version Downloads Last updated
3.0.0 136 11/23/2024
2.0.2 180 11/1/2024
2.0.1 210 7/9/2024
2.0.0 168 5/18/2024
1.9.0 18,592 11/19/2023
1.8.7 210 9/15/2023
1.8.6 8,201 6/16/2023
1.8.5 204 4/14/2023
1.8.4 269 3/17/2023
1.8.3 263 2/15/2023
1.8.2 7,666 1/11/2023
1.8.1 311 12/17/2022
1.8.0 374 11/11/2022
1.7.0 461 9/4/2022
1.6.1 10,867 6/8/2022
1.6.0 8,678 11/13/2021
1.5.2 344 8/16/2021
1.5.1 354 4/26/2021
1.5.0 338 4/25/2021
1.4.1 365 2/6/2021
1.4.0 425 12/7/2020
1.3.0 475 7/7/2020
1.2.1 548 3/31/2020
1.2.0 514 12/15/2019
1.1.0 543 12/10/2019
1.0.0 511 12/2/2019