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
                    
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="Zooper.CSharp.Logging" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zooper.CSharp.Logging" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Zooper.CSharp.Logging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zooper.CSharp.Logging --version 0.0.2
                    
#r "nuget: Zooper.CSharp.Logging, 0.0.2"
                    
#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.
#:package Zooper.CSharp.Logging@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zooper.CSharp.Logging&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Zooper.CSharp.Logging&version=0.0.2
                    
Install as a Cake Tool

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 535 10/2/2021
0.0.1 516 10/2/2021

# 0.0.1
- Implemented basic logger
# 0.0.2
- Testings for Github actions