LothiumLogger 1.4.0

dotnet add package LothiumLogger --version 1.4.0
NuGet\Install-Package LothiumLogger -Version 1.4.0
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="LothiumLogger" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LothiumLogger --version 1.4.0
#r "nuget: LothiumLogger, 1.4.0"
#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 LothiumLogger as a Cake Addin
#addin nuget:?package=LothiumLogger&version=1.4.0

// Install LothiumLogger as a Cake Tool
#tool nuget:?package=LothiumLogger&version=1.4.0

LothiumLgger NuGet Version NuGet Downloads

Getting Started

LothiumLogger is a simple easy-to-use Logger Library for .Net applications written entirely in C# for fun, it offers a basic and easy syntax and give flexybility to the final user. The idea behind this project is to create a simple interactive way to catch events from your application in the simpliest and easiest way possible just by instance a variable and use it! You can install LothiumLogger directly from NuGet using the NuGet Manager inside Visual Studio or with this command:

dotnet add package LothiumLogger

This library provide a simple configuration steps, the first thing to do is create a new LoggerSettings and configure all the settings that the logging process will use. One way is to create a new LoggerSettings class, configure it and pass it to the constructor, the other way is to do it directly inside the constructor with a delegate action.

var logger = new Logger(settings => {
    // Add settings here
});

The library provides a built-in Sink, one for logging to the OS's console and one for logging to one or more file. To configure this two sink you need a specific dedicated SinkOptions configuration to provide them, the process to do that is the same of the LoggerSettings class. Every sink will use different property from the SinkOptions class so it's not required to populate all of them, this depends on what sink you are currently configuring.

var logger = new Logger(settings => {
    // Console Sink
    settings.AddConsoleSink(options => {
        // Add options here 
    });

    // Default File Sink For Log Events
    settings.AddFileSink(options => {
        // Add options here
    });
});

Console Sinker

The console's sink offer the ability to write logs directly to the IDE's debug console / OS's console to track events while running your projects. Like mentioned before, this sink required a set of options passed through a dedicated object to properly working. This options class have different type of property, the minimum required are the following:

var logger = new Logger(settings => {
    settings.AddConsoleSink(options => {
        options.Enabled = true;                                             // Required => Defines if the sink is enabled for writing the events
        options.DateFormat = LogDateFormatEnum.Standard;                    // Required => Defines the format for the date inside the log events
        options.LoggingRule = new(LogLevelEnum.Debug, false);               // Required => Defines the rule for writing the events
    });
});

File Sinker

The file's sink offer the ability to write logs to one or more files/folders, like mentioned before, this sink required a set of options passed through a dedicated object to properly working. This options class have different type of property, the minimum required are the following:

var logger = new Logger(settings => {
    settings.AddFileSink(options => {
        options.Enabled = true;                                                             // Required => Defines if the sink is enabled for writing the events
        options.DateFormat = LogDateFormatEnum.Standard;                                    // Required => Defines the format for the date inside the log events
        options.LoggingRule = new(LogLevelEnum.Normal, false);                              // Required => Defines the rule for writing the events
        options.FileRule = new(                                                             // Required => Defines the type, the path and the name of the file
            LogFileTypeEnum.GenericLog, 
            Path.Combine("var", "logs"),
            "LogName"
        );                                                                                  
    });
});

Custom Sinker

The library provides the ability to use custom sink in addition to the built-in ones. To define a custom sink you need to extends the GenericSink class and override the Write() method The configuration object offer the ability to create and add a customized sinker, the only thing to do is create a new class and extender the ISinkers interface:

using LothiumLogger.Interfaces;

public class CustomSink : GenericSink
{
    public CustomSink(SinkOptions setting) : base(setting) { }

    public CustomSink(Action<SinkOptions> settings) : base(settings) { }

    public override void Write(LogEvent logEvent)       // Override required if you want to add custom logic during the writing of the log events
    {
        base.Write(logEvent)        // Do this if you need the default writing before your custom logic //

        // Put here your custom logic //
    }
}

Logger Methods

After the creation of the logger instance, there are 6 different types of logging level: Normal, Debug, Information, Warning, Error & Fatal. Each one have their separated methods for writing new logging events:

logger.Write("Log Message");                            // Defualt normal message
logger.Debug("Debug Log Message");                      // Debug message when testing code
logger.Information("Info Log Message");                 // Info message
logger.Warning("Warn Log Message");                     // Warning message
logger.Error("Err Log Message");                        // Error message
logger.Fatal("Fatal Log Message");                      // Fatal message

Object Serialization

The library gave the user the ability to seraize an object inside the log message or a one or more property to keep track of real time changes. For serialize an object or a Property Name is required the Type Name likes this example:

Person person = new Person() 
{
    Name = "Andrea",
    Surname = "Santinato",
    Age = 25
};

logger.Information("Created Person: {@Person}", person);
logger.Information("Person Name: {@Person.Name} {@Person.Surname}", person);
logger.Information("Person Age: {@Person.Age}", person);

For this methods to work the parameter's name must be equal to the object class's type, in this case the class name is 'Person' When you need to serialize one or more object property, the library need a combination of the object's type name and the property name In the end the library can serialize an external independent variable passed to the methods:

string example = "Test Variable";
logger.Debug("Variable Value: {@example}", example);

If an error occured while executing the code and need to keep track of exception, the library offer the ability to serialize an exception object directly to the log message:

try 
{
    // Some Code Here...
    throw new Exception("Test exception example!!");
}
catch (Exception exception)
{
    // Log the exception
    logger.Error(exception);
}

Bug Reports

If you want to contribute to this project, you can send a pull request to the GitHub Repository and i'll be happy to add it to the project. In The feature i'll separate the Master Branch from the Develop Branch

I welcome any type of bug reports and suggestions through my GitHub Issue Tracker.

Latest Release Changes

Redesign the library configuration classes to match a simple creation and configuration.

  • Added class configuration for Sink classes.
  • Changed the logic of the internal writing events.
  • Added asynchronous methods.

LothiumLogger is copyright © 2024 - Provided under the GNU General Public License v3.0.

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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
1.4.0 140 1/11/2024
1.3.0 113 9/7/2023
1.2.0 108 8/21/2023
1.1.0 110 8/18/2023
1.0.0 141 8/10/2023

Completely change the core logic of the library and simplified the sink's writing methods.

The Logger class implementation now is simply than ever with a dedicated class extendible during time.

Every single Sink can benefit from the SinkOptions class that provide a set of property that can change for every single sink instances.