Zooper.CSharp.Logging
0.0.2
dotnet add package Zooper.CSharp.Logging --version 0.0.2
NuGet\Install-Package Zooper.CSharp.Logging -Version 0.0.2
<PackageReference Include="Zooper.CSharp.Logging" Version="0.0.2" />
<PackageVersion Include="Zooper.CSharp.Logging" Version="0.0.2" />
<PackageReference Include="Zooper.CSharp.Logging" />
paket add Zooper.CSharp.Logging --version 0.0.2
#r "nuget: Zooper.CSharp.Logging, 0.0.2"
#:package Zooper.CSharp.Logging@0.0.2
#addin nuget:?package=Zooper.CSharp.Logging&version=0.0.2
#tool nuget:?package=Zooper.CSharp.Logging&version=0.0.2
This library provides a wrapper for loggers. Some examples are included. Note: This library is part of the whole zooper lib family.
Getting started
Import the Nuget package:
nuget install Zooper.CSharp.Logging
Usage
To use the logger you have to instantiate at least 2 classes:
The log writer
The logger needs a writer it can write the log to. This can be the console, an api or a file. You can also define multiple writer which the logger writes to simultanously.
using System;
using System.Threading.Tasks;
namespace Zooper.CSharp.Logging.Writers
{
public class ConsoleLogWriter : LogWriter
{
public override Task WriteAsync(string message)
{
Console.WriteLine(message);
return Task.CompletedTask;
}
}
}
This is an example of a console writer which also can be found inside this package.
var writer = new ConsoleLogWriter();
The logger
After that, you need to pass the writer to the logger:
var logger = new Logger(minimumLoggingLevel, logWriters);
The minimumLoggingLevel defines what type of log should be logged. These options are available (starting from the lowest to the highest):
public enum LogLevel {
verbose,
debug,
info,
warning,
error,
wtf,
}
The logWriters expects a list of writers like our ConsoleLogWriter.
After all is set up, you can log messages like so:
logger.LogInfoAsync('Your message');
or with StackTrace
logger.LogInfoAsync('Your message', Environment.StackTrace);
or
logger.Log('Your message', LogLevel.Info, Environment.StackTrace);
Formatting the output
Use the LogFormatter base class to dress up the output. An example class is also included named PrettyFormatter.
var formatter = new PrettyFormatter();
Then you can pass it to our logger:
var logger = new Logger(<minimumLoggingLevel>, <logWriters>, formatter);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net5.0
- Zooper.CSharp.Core (>= 0.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
# 0.0.1
- Implemented basic logger
# 0.0.2
- Testings for Github actions