PvWay.LoggerService.SeriConsole.nc8
1.0.3
See the version list below for details.
dotnet add package PvWay.LoggerService.SeriConsole.nc8 --version 1.0.3
NuGet\Install-Package PvWay.LoggerService.SeriConsole.nc8 -Version 1.0.3
<PackageReference Include="PvWay.LoggerService.SeriConsole.nc8" Version="1.0.3" />
paket add PvWay.LoggerService.SeriConsole.nc8 --version 1.0.3
#r "nuget: PvWay.LoggerService.SeriConsole.nc8, 1.0.3"
// Install PvWay.LoggerService.SeriConsole.nc8 as a Cake Addin #addin nuget:?package=PvWay.LoggerService.SeriConsole.nc8&version=1.0.3 // Install PvWay.LoggerService.SeriConsole.nc8 as a Cake Tool #tool nuget:?package=PvWay.LoggerService.SeriConsole.nc8&version=1.0.3
pvWay SeriLoggerService for dotNet Core 8
Description
This nuget implements the ILoggerService as a simple stdout console using the well known Serilog(tm) console skin nuGet
Severity enum
public enum SeverityEnu
{
Ok, // "O"
Trace, // "T"
Debug, // "D"
Info, // "I"
Warning, // "W"
Error, // "E"
Fatal // "F"
}
Methods
All methods include both a synchronous and an asynchronous signature.
The class also implement the ILogger interface (microsoft.logging)
See here after the main methods:
void Log(
string message,
SeverityEnu severity = SeverityEnu.Debug,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = -1);
Task LogAsync(
string message,
SeverityEnu severity = SeverityEnu.Debug,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = -1);
void Log(
IEnumerable<string> messages,
SeverityEnu severity,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = -1);
Task LogAsync(
IEnumerable<string> messages,
SeverityEnu severity,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = -1);
void Log(
Exception e,
SeverityEnu severity = SeverityEnu.Fatal,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = -1);
Task LogAsync(
Exception e,
SeverityEnu severity = SeverityEnu.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);
Injection
The PvWaySerilogConsoleLogger method extends the IServiceCollection
The default lifetime is Scoped and the default minimum log level is Trace... i.e. logging everything
public static void AddPvWaySeriConsoleLoggerService(
this IServiceCollection services,
SeverityEnu minLogLevel = SeverityEnu.Trace,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
services.TryAddSingleton<ILoggerServiceConfig>(_ =>
new LoggerServiceConfig(minLogLevel));
var sd = new ServiceDescriptor(
typeof(ILoggerService),
typeof(SerilogConsoleService),
lifetime);
services.Add(sd);
var sd2 = new ServiceDescriptor(
typeof(ISeriConsoleLoggerService),
typeof(SerilogConsoleService),
lifetime);
services.Add(sd2);
}
Static factories
The PvWaySerilogConsoleLogger static class also exposes two public Create methods enabling to factor the service from your own code
public static ISeriConsoleLoggerService Create(
SeverityEnu minLogLevel = SeverityEnu.Trace)
{
return new SerilogConsoleService(
new LoggerServiceConfig(minLogLevel));
}
public static ISeriConsoleLoggerService<T> Create<T>(
SeverityEnu minLogLevel = SeverityEnu.Trace)
{
return new SerilogConsoleService<T>(
new LoggerServiceConfig(minLogLevel));
}
Usage
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PvWay.LoggerService.Abstractions.nc8;
using PvWay.LoggerService.SeriConsole.nc8;
Console.WriteLine("Hello, SeriConsoleLoggerService");
Console.WriteLine();
var services = new ServiceCollection();
services.AddPvWaySeriConsoleLoggerService();
var sp = services.BuildServiceProvider();
var ls = sp.GetService<ILoggerService>()!;
ls.Log("This is a trace test log message", SeverityEnu.Trace);
ls.Log("This is a debug test log message");
ls.Log("This is an info test log message", SeverityEnu.Info);
ls.Log("This is a warning test log message", SeverityEnu.Warning);
ls.Log("This is an error test log message", SeverityEnu.Error);
ls.Log("This is a fatal test log message", SeverityEnu.Fatal);
ls.Log(LogLevel.Trace, "MsLog trace");
Happy coding
Product | Versions 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. |
-
net8.0
- PvWay.LoggerService.nc8 (>= 1.0.4)
- Serilog.Sinks.Console (>= 5.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Uses LoggerService 1.0.4