PvWay.LoggerService.nc6 2.0.0

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

// Install PvWay.LoggerService.nc6 as a Cake Tool
#tool nuget:?package=PvWay.LoggerService.nc6&version=2.0.0                

pvWay Logger Service for dotNet core 6

Description

This nuget provides several very intuitive LoggerService implementations of the PvWay.LoggerService.Abstractions.nc6 ILoggerService interface :

  • ConsoleLogger
  • MuteLogger
  • Microsoft Logger
  • PersistenceLogger
  • Ms Console Logger
  • Multichannel Logger

ConsoleLogger

  • This colorful implementation uses Console.WriteLine outputting logs to the standard out.

Mutelogger

  • As the name sounds this implementation can be used to injecting a silent logger. This can be handy for unit testing.

Microsoft Logger

  • Uses the Microsoft.Extensions.Logging.Logger for outputting logs

Persistent Logger

  • Enables you to connect any persistence layer for storing logs into the storage of your choice
  • Have a look to
    • the Microsoft SQL persistence layer PvWay.LoggerService.MsSqlLogWriter.nc6 nuGet package
    • or the PostgreSQL persistence layer PvWay.LoggerService.PgSqlLogWriter.nc6 nuGet package

Methods

All methods include both a synchronous and an asynchronous signature.

See here after the main methods:

void Log(
    string message,
    SeverityEnum severity = SeverityEnum.Debug,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

Task LogAsync(
    string message,
    SeverityEnum severity = SeverityEnum.Debug,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);
        
void Log(
    IEnumerable<string> messages,
    SeverityEnum severity,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

Task LogAsync(
    IEnumerable<string> messages,
    SeverityEnum severity,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

void Log(
    Exception e,
    SeverityEnum severity = SeverityEnum.Fatal,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

Task LogAsync(
    Exception e,
    SeverityEnum severity = SeverityEnum.Fatal,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

void Log(
    IMethodResult result,
    string? topic,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

Task LogAsync(
    IMethodResult result,
    string? topic,
    [CallerMemberName] string memberName = "",
    [CallerFilePath] string filePath = "",
    [CallerLineNumber] int lineNumber = -1);

Usage

using Microsoft.Extensions.DependencyInjection;
using PvWay.LoggerService.nc6;

namespace PvWay.LoggerServiceLab.nc6;

public class ConsoleLoggerDemo
{
    public async Task<double> HowToUseTheConsoleLogger(
        double x)
    {
        Console.WriteLine("Hello, ConsoleLoggerService");
        Console.WriteLine("---------------------------");
        Console.WriteLine();

        var consoleLs = PvWayLoggerService.CreateConsoleLoggerService();

        try
        {
            // dividing by zero throws an exception
            return x / 0;
        }
        catch (Exception e)
        {
            await consoleLs.LogAsync(e);
            throw;
        }
    }

    public async Task AndWithDependencyInjection()
    {
        var services = new ServiceCollection();

        // provisions the different loggerServices
        // ConsoleLogger, MuteLogger, MsConsoleLogger...
        services.AddPvWayLoggerServices(ServiceLifetime.Transient);

        var sp = services.BuildServiceProvider();

        // Retrieve the ConsoleLogger
        var consoleLs = sp.GetService<IPvWayConsoleLoggerService>()!;

        // Use it
        await consoleLs.LogAsync("Not that complex after all");
    }

}

See Also

Take also a look to the MethodResultWrapper nuGet

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on PvWay.LoggerService.nc6:

Package Downloads
pvWay.MethodResultWrapper.nc6

Provides a generic wrapper that returns whether or not a method succeeded or failed carrying the method result on success or a list of notifications/errors in case of failure

PvWay.LoggerService.PgSqlLogWriter.nc6

PostgreSQL implementation of the pvWay.LoggerService.Abstractions.nc6 that persists logs into a table in a PostgreSQL database

PvWay.LoggerService.SeriConsole.nc6

Implements the ILoggerService as a simple stdout console using the well known Serilog(tm) console skin logger.

PvWay.LoggerService.MsSqlLogWriter.nc6

Microsoft SQL implementation of the pvWay.LoggerService.Abstractions.nc6 that persists logs into a table in a MsSQL database

PvWay.LoggerService.Console.nc6

Implements the ILoggerService as a simple stdout console using Console.WriteLine statements. The output is colored depending on the severity.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.1 269 8/12/2024
4.0.0 111 8/11/2024
3.0.4 237 8/4/2024
3.0.3 86 8/4/2024
3.0.2 185 8/4/2024
3.0.1 180 8/3/2024
3.0.0 176 8/2/2024
2.0.1 290 8/28/2023
2.0.0 181 8/25/2023
1.0.1 143 8/25/2023
1.0.0 230 6/7/2023

More Loggers, Dependency Injection