TinyLogger 2.0.2
dotnet add package TinyLogger --version 2.0.2
NuGet\Install-Package TinyLogger -Version 2.0.2
<PackageReference Include="TinyLogger" Version="2.0.2" />
paket add TinyLogger --version 2.0.2
#r "nuget: TinyLogger, 2.0.2"
// Install TinyLogger as a Cake Addin #addin nuget:?package=TinyLogger&version=2.0.2 // Install TinyLogger as a Cake Tool #tool nuget:?package=TinyLogger&version=2.0.2
TinyLogger
Tiny extendable logger that plugins into Microsoft.Extensions.Logging
Because sometimes you don't want to use a full logging framework but still want readable console output and log files.
Simple example
If builder is an instance of ILoggingBuilder
you can simply add the console logger like this:
builder.AddTinyConsoleLogger();
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 =>
{
// Optionally extend log fields with new or modified data
options.Extenders.Add(new SampleExceptionExtender());
// Select a custom message template
options.Template = MessageTemplates.DefaultTimestamped;
// Render to console
options.AddConsole();
// Render to a file with a set name
options.AddFile("example.log");
// Render to file with rolling name, when the timestamp changes the file changes
options.AddRollingFile(() => $"example-{DateTime.Now.ToString("yyyyMMdd-HHmm")}.log");
});
Screenshot of ConsoleApp sample
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.
Sample with TinyLogger
Sample with standard console logger for comparison
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.
The default behavior is to keep all messages.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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. |
.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
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.10)
- PolySharp (>= 1.14.1)
- System.Interactive.Async (>= 6.0.1)
- System.Threading.Channels (>= 8.0.0)
-
net6.0
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.10)
-
net8.0
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.ObjectPool (>= 8.0.10)
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 |
---|---|---|
2.0.2 | 124 | 11/1/2024 |
2.0.1 | 204 | 7/9/2024 |
2.0.0 | 162 | 5/18/2024 |
1.9.0 | 16,822 | 11/19/2023 |
1.8.7 | 206 | 9/15/2023 |
1.8.6 | 8,197 | 6/16/2023 |
1.8.5 | 200 | 4/14/2023 |
1.8.4 | 265 | 3/17/2023 |
1.8.3 | 259 | 2/15/2023 |
1.8.2 | 7,661 | 1/11/2023 |
1.8.1 | 307 | 12/17/2022 |
1.8.0 | 364 | 11/11/2022 |
1.7.0 | 457 | 9/4/2022 |
1.6.1 | 10,863 | 6/8/2022 |
1.6.0 | 8,674 | 11/13/2021 |
1.5.2 | 340 | 8/16/2021 |
1.5.1 | 350 | 4/26/2021 |
1.5.0 | 334 | 4/25/2021 |
1.4.1 | 359 | 2/6/2021 |
1.4.0 | 418 | 12/7/2020 |
1.3.0 | 469 | 7/7/2020 |
1.2.1 | 542 | 3/31/2020 |
1.2.0 | 508 | 12/15/2019 |
1.1.0 | 536 | 12/10/2019 |
1.0.0 | 505 | 12/2/2019 |