Bit.Logger
2.0.0
dotnet add package Bit.Logger --version 2.0.0
NuGet\Install-Package Bit.Logger -Version 2.0.0
<PackageReference Include="Bit.Logger" Version="2.0.0" />
paket add Bit.Logger --version 2.0.0
#r "nuget: Bit.Logger, 2.0.0"
// Install Bit.Logger as a Cake Addin
#addin nuget:?package=Bit.Logger&version=2.0.0
// Install Bit.Logger as a Cake Tool
#tool nuget:?package=Bit.Logger&version=2.0.0
Logger for .NET Core
Logger for .NET Core Apps that enables logging to different sources
One logger to log them all
Console
If the code that implements the logger uses a console messages can be sent to it
Database
A SQLite database is created every hour to keep small files in a path that is configurable through code (if no path is set, the assembly location will be selected by default)
File
A file is created every hour to keep small files in a path that is configurable through code (if no path is set, the assembly location will be selected by default)
Custom
You can create custom sources to send the messages to a different output of your preference i.e. (FTP, SQL Server, CloudWatch, etc)
Configurable
All the provided sources and the ones you may create can be configured to only show specific data according to the needs of your business
How to use with default sources
class Program
{
// Inject in a service provider
static void Main(string[] args)
{
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
// Create service provider
var serviceProvider = serviceCollection.BuildServiceProvider();
// Run app
serviceProvider.GetService<Test>().It();
}
private void ConfigureServices()
{
// Build logger
ILogger logger = new Logger()
.AddConsoleSource()
.AddDatabaseSource()
.AddFileSource();
// Add access to generic ILogger
serviceCollection.AddSingleton(logger);
// Add the Test class
serviceCollection.AddTransient<Test>();
}
}
// Somewhere else in the code
internal class Test
{
private readonly ILogger logger;
internal Test(ILogger logger) => this.logger = logger;
internal void It() => logger.Information("sample");
}
// Call it
var args = new string[] {};
Program.Main(args);
// this should produce an output to a file, database and console and display a message like this
// <INFORMATION> 2019-03-06 23:02:56 [Test::It] sample
How the Log Levels work
// This is the Level enum
public enum Level
{
Trace = 0,
Debug = 1,
Verbose = 2,
Information = 3,
Warning = 4,
Error = 5,
Critical = 6,
None = 7
}
public void Test()
{
var consoleConfiguration = new ConsoleConfiguration
{
Level = Level.Trace // Do not ignore any level and log all messages
};
var databaseConfiguration = new DatabaseConfiguration
{
Level = Level.Warning // Ignore any lower levels and only log messages equal or greater than Warning
};
var fileConfiguration = new FileConfiguration
{
Level = Level.Critical // Ignore any lower levels and only log Critical messages
};
// Build logger
ILogger logger = new Logger()
.AddConsoleSource(consoleConfiguration)
.AddDatabaseSource(databaseConfiguration)
.AddFileSource(fileConfiguration);
logger.Trace("test"); // this will only be sent to the console
logger.Warning("test"); // this will be sent to the console and the database
logger.Critical("test"); // this will be sent to the console, the database and the file
}
See the samples
Console application with the 3 default loggers configured
Product | Versions 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 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 | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.EntityFrameworkCore.Design (>= 2.2.1)
- Microsoft.EntityFrameworkCore.Sqlite (>= 2.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.