Ksh.Logger 2024.1.3-rc.3

This is a prerelease version of Ksh.Logger.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Ksh.Logger --version 2024.1.3-rc.3                
NuGet\Install-Package Ksh.Logger -Version 2024.1.3-rc.3                
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="Ksh.Logger" Version="2024.1.3-rc.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ksh.Logger --version 2024.1.3-rc.3                
#r "nuget: Ksh.Logger, 2024.1.3-rc.3"                
#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 Ksh.Logger as a Cake Addin
#addin nuget:?package=Ksh.Logger&version=2024.1.3-rc.3&prerelease

// Install Ksh.Logger as a Cake Tool
#tool nuget:?package=Ksh.Logger&version=2024.1.3-rc.3&prerelease                

Ksh.Logger

The most flexible logger on the planet!

Simple usage

var propagators = new List<ILogMessagePropagator> {
    new ConsoleLoggerPropagator(),
    new FileLoggerPropagator("path.to.log")
};
var logger = new StandardLogger(propagators);

logger.Info("hello world");

It looks simpler, but you have also the direct dependencies and violate the DIP (dependency inversion principle).

Using with Microsoft Dependency Injection

var services = new ServiceCollection();
services.AddKshLogger();

var kernel = services.BuildServiceProvider();
var loggerFactory = kernel.GetService<ILoggerFactory>()!;

loggerFactory.AddConsoleLogger();
loggerFactory.AddFileLogger("path.to.log");

var logger = loggerFactory.CreateLogger();
logger.Info("hello world");

You are already ready to log into a file as well as into console. Of course, you can skip the console or the file logger if you wish.

Customization

As mentioned, this Logger is very flexible. It is even possible to connect multiple existing logging frameworks.

Propagators

The power of this Logger are the Propagators

Here is an example, how to be notified if your crashed and reported a fatal error.

public class CustomPropagator(IEmailClient emailClient) : ILogMessagePropagator
{
    public void Propagate(LogMessage message)
    {
        if (message.Severity == LogSeverity.Fatal)
        {
            emailClient.SendEmail(message.Message);
        }
    }
}

Just put this propagator into your factory or directly into the logger.

loggerFactory.AddPropagator(new CustomPropagator(emailClient));
Product Compatible and additional computed target framework versions.
.NET 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. 
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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.2.2-rc.1 28 5/2/2024
2024.2.1 81 5/2/2024
2024.1.3 126 3/23/2024
2024.1.3-rc.4 60 3/18/2024
2024.1.3-rc.3 56 3/18/2024
2024.1.2 118 3/18/2024
2024.1.2-rc.2 54 3/18/2024
2024.1.1 126 3/18/2024