Pustalorc.Logging 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pustalorc.Logging --version 1.0.3                
NuGet\Install-Package Pustalorc.Logging -Version 1.0.3                
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="Pustalorc.Logging" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pustalorc.Logging --version 1.0.3                
#r "nuget: Pustalorc.Logging, 1.0.3"                
#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.
// Install Pustalorc.Logging as a Cake Addin
#addin nuget:?package=Pustalorc.Logging&version=1.0.3

// Install Pustalorc.Logging as a Cake Tool
#tool nuget:?package=Pustalorc.Logging&version=1.0.3                

Logging Library NuGet

This library is the core of the functionality for logging. You can install it using NuGet.

Usage

There are many ways this library can be used.
You can instantiate a pipe directly and log to console (ConsolePipe) or to a file (FilePipe).
You can instantiate a logger directly to log to multiple pipes of your chosing at once (DefaultLogger).
Or you can use the LogManager class and let the library handle all the instantiation for you.
Due to this, I will be focusing on the main case of just letting the LogManager class handle all the instantiation.

If you do not wish to configure the outputs

If you do not wish to configure where your logs will go to, you can directly call the following example methods to log with the preset log levels:

LogManager.Trace(object message);
LogManager.Debug(object message);
LogManager.Information(object message);
LogManager.Warning(object message);
LogManager.Error(object message);
LogManager.Fatal(object message);

All of these log levels are documented for their expected purpose, but you are free to use them however you see fit.
Additionally, if you implement a custom log level, or wish to specify an exact level yourself without the helper methods, you can use LogManager.Write(object message, ILogLevel level)

The reason all of these methods use object for the messages, rather than string is to have a similar functionality to Console.WriteLine(), to which you can pass an exception object, and the .NET runtime will still write the exception to console, rather than needing developers to call .ToString() on any object they wish to log to console.

The LogManager is a static class, so no instantiation is needed, but this class instantiates an ILoggerManager (specifically DefaultLoggerManager) in the field LoggerManager which handles creating new Loggers for each assembly, linking a logger to a calling assembly, and constructing any new pipes and loggers.
This field can be overwritten if you wish to extend which ILogPipes the library can create, as well as any internal functionality for loggers.

If you do wish to configure the outputs

When not configuring the logger for your assembly before calling it, the pipes will limit their output to the Information level.
This might not be desired, or you might want to limit output to one pipe, or have multiple file outputs for each log level, so this is where you can call the following method:

LogManager.UpdateConfiguration(ILoggerConfiguration configuration);

With this method, you can update the ILogger instance that is linked to your Assembly and change which pipes it uses, the maximum and minimum log levels for each pipe, as well as the log format for each pipe.

To construct a configuration, you will have to create a few classes, starting with a class that inherits from ILoggerConfiguration:

public class LoggerConfiguration : ILoggerConfiguration
{
    
    public List<IPipeConfiguration> PipeSettings =>
    [
        new ConsolePipeConfiguration(),
        new FilePipeConfiguration()
    ];

    public sealed class ConsolePipeConfiguration : DefaultConsolePipeConfiguration
    {
        public override byte MaxLogLevel => LogLevel.Debug.Level;
    }

    public sealed class FilePipeConfiguration : DefaultFilePipeConfiguration
    {
        public override byte MaxLogLevel => LogLevel.Debug.Level;
    }
}

In this configuration class, you can set which pipes to use by using a new IPipeConfiguration and setting PipeName to the name of the class you wish to use. In the example, we want to increase the log level to allow Debug level logs to be written to both the ConsolePipe and the FilePipe without changing any of the other values, so we use their default configuration types and we override MaxLogLevel.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pustalorc.Logging:

Package Downloads
Pustalorc.BuildableAbstractions.API

Unturned Library to provide abstractions for Barricades and Structures, as Buildables. Also includes some useful patches for events that don't exist by default.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 135 8/3/2024
1.0.3 104 7/18/2024
1.0.2 98 7/18/2024
1.0.1 102 7/18/2024

Fixed an issue with FilePipe not adding a new line at end of lines.