Splat.TransportLogger 1.0.0

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

// Install Splat.TransportLogger as a Cake Tool
#tool nuget:?package=Splat.TransportLogger&version=1.0.0

Splat.TransportLogger

A logger that let you publish your message on different output

Why Splat.TransportLogger?

When developping app, logging to the console is usefull... until it's not usefull anymore. What if you are developping a mobile app that uses geofencing and you need to log the trace of the geofencing events? What if you want to send your exceptions callstack directly to a ticket manager? what if you want to receive a slack notification each time a certai event occur? Worry no more: Splat.TransportLogger is here! Implementing the interface ILogger of the splat package (because we love splat and we don't need another ILogger interface) TransportLogger let you register 'Transport' that will carry your logs to where you want them to appear.

Installing Splat.TransportLogger

Just look it up on nuget

How it works

Creating a Transport

A transport is a class that implements the ITransport interface. It is responsible for carrying a message to where you want it to arrive. Here is a (simple) transport that will publish all debug message to slack message to a slack channel

public class TextToSlackTransport : ITransport
{
    private readonly Uri _uri;
    public TextToSlackTransport(string slack_webhook)
    {
        _uri = new Uri(slack_webhook);
    }
    
    public void OnLogReceived(object message, LogLevel level, Type type = null)
    {
        if (level != LogLevel.Debug) return;

        var json = $"{{ 'Text': {message.ToString()} }}";
        
        using var client = new WebClient();
        
        client.UploadString(_uri, json);
    }
}

Creating a logger and adding transport

Creating a Transport logger and adding transport to it is very straightforward. Here we create a logger, if we build in debug, we add the slack transport. Once created, the logger is register in the service locator.

public void CreateLogger()
{
    var logger = new TransportLogger();
#if DEBUG
    logger.AddTransport(new SlackTransport());
#endif
    Locator.CurrentMutable.RegisterConstant(logger, typeof(ILogger));
}

Writing

Once this is done, you can use the API of ILogger to write to your transport. everytime you write something in the logger, all your transport will be called.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

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
1.0.0 505 9/29/2020

First release