Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

TheKrystalShip/Logging

Repository files navigation

TheKrystalShip.Logging

Downloads Version Build Status
Downloads Version Build

Manual NuGet package download

Setup

The two methods that ILogger<T> provides are .LogError() and .LogInformation(), with a few overloads each, which sould cover the basic needs when logging to the console.

You can create instances whenever you want:

using TheKrystalShip.Logging

// ...

public class MyClass
{
    private readonly ILogger<MyClass> _logger;

    public MyClass()
    {
        _logger = new Logger<MyClass>(LoggerStyle.Default);
    }
}

Or you can use the provided IServiceCollection extension enabling dependency injection:

! This makes the output default to LoggerStyle.Compact

Services:

using TheKrystalShip.Logging.Extensions

// ...

services = new ServiceCollection()
    .AddLogger()
    .BuildServiceProvider();

Injection:

using TheKrystalShip.Logging;

// ...

public class MyClass
{
    private readonly ILogger<MyClass> _logger;

    public MyClass(ILogger<MyClass> logger)
    {
        _logger = logger;
    }
}

Output

Format: [DateTime] [LineNumber] Type - Message

LoggerStyle.Compact

CompactView

LoggerStyle.Default

Default view

Releases

No releases published

Packages

No packages published

Languages