TinyLogger 1.5.2
See the version list below for details.
dotnet add package TinyLogger --version 1.5.2
NuGet\Install-Package TinyLogger -Version 1.5.2
<PackageReference Include="TinyLogger" Version="1.5.2" />
paket add TinyLogger --version 1.5.2
#r "nuget: TinyLogger, 1.5.2"
// Install TinyLogger as a Cake Addin #addin nuget:?package=TinyLogger&version=1.5.2 // Install TinyLogger as a Cake Tool #tool nuget:?package=TinyLogger&version=1.5.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.
For production scenarios you should probably use a more full featured logging framework since they tend to be battle tested. TinyLogger is more intended for development scenarios and as such does not have as many features, but that's why it's tiny.
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 is compatible. 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 was computed. 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 (>= 5.0.0)
- Microsoft.Extensions.Logging (>= 5.0.0)
- System.Interactive.Async (>= 5.0.0)
- System.Threading.Channels (>= 5.0.0)
-
net5.0
- Microsoft.Extensions.Logging (>= 5.0.0)
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 | 99 | 11/1/2024 |
2.0.1 | 198 | 7/9/2024 |
2.0.0 | 160 | 5/18/2024 |
1.9.0 | 16,129 | 11/19/2023 |
1.8.7 | 204 | 9/15/2023 |
1.8.6 | 8,195 | 6/16/2023 |
1.8.5 | 198 | 4/14/2023 |
1.8.4 | 263 | 3/17/2023 |
1.8.3 | 257 | 2/15/2023 |
1.8.2 | 7,660 | 1/11/2023 |
1.8.1 | 305 | 12/17/2022 |
1.8.0 | 362 | 11/11/2022 |
1.7.0 | 455 | 9/4/2022 |
1.6.1 | 10,861 | 6/8/2022 |
1.6.0 | 8,672 | 11/13/2021 |
1.5.2 | 336 | 8/16/2021 |
1.5.1 | 348 | 4/26/2021 |
1.5.0 | 332 | 4/25/2021 |
1.4.1 | 357 | 2/6/2021 |
1.4.0 | 417 | 12/7/2020 |
1.3.0 | 467 | 7/7/2020 |
1.2.1 | 540 | 3/31/2020 |
1.2.0 | 506 | 12/15/2019 |
1.1.0 | 534 | 12/10/2019 |
1.0.0 | 503 | 12/2/2019 |