Downloads | Version | Build Status |
---|---|---|
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
using TheKrystalShip.Logging.Extensions
// ...
services = new ServiceCollection()
.AddLogger()
.BuildServiceProvider();
using TheKrystalShip.Logging;
// ...
public class MyClass
{
private readonly ILogger<MyClass> _logger;
public MyClass(ILogger<MyClass> logger)
{
_logger = logger;
}
}
Format: [DateTime] [LineNumber] Type - Message