LoggerLib 1.2.2

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

// Install LoggerLib as a Cake Tool
#tool nuget:?package=LoggerLib&version=1.2.2

General info

Logger for your C# project<br> Saving logs to the console and to the .log or .txt files.<br> You can also save logs to the database (MySQL and PostgreqSQL).<br> Old files are backed up to reduce the size of the logs.<br>

Installation

PM> Install-Package LoggerLib -Version 1.2.1

or

> dotnet add package LoggerLib --version 1.2.1

Usage

Example 1

static void Main(string[] args)
{
    // If you want to change log directory or log extension
    LoggerConfiguration.LogsDir = "SomePath/Logs"; // Default: "logs"
    LoggerConfiguration.LogsExtension = "txt"; // Recommended: `log` or `txt` | Default: "log"
    
    // What type of logs should be logged
    LoggerConfiguration.MinimumLogLevel = LogType.Information;
    
    // Initialize logger
    Logger.Init();

    Logger.Info("Message");
    Logger.Warning("Message");
    Logger.Error("Message");
    Logger.Debug("Message");

    Logger.Info(new Exception("Exception message"));
    Logger.Warning(new Exception("Exception message"));
    Logger.Error(new Exception("Exception message"));
    Logger.Debug(new Exception("Exception message"));
}
Note

You don't need to declare LoggerConfiguration, values will be assigned by default.

Example 2

If you want this to be your main logger Example in the ASP.NET 6.0

var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Host.UseLoggerLib();

Logger.Logger.Init();

Check out the full example in the <a href="https://github.com/KimPiks/LoggerLib/tree/main/Example">Sample Application</a> in the repository

Example output

Example file name

08-03-2021.log

Example content

[13:56:47][INFO] Message
[13:56:47][WARNING] Message
[13:56:47][ERROR] Message
[13:56:47][DEBUG] Message

Example console content

[15:04:15][INFO] |Microsoft.Hosting.Lifetime| - Now listening on: https://localhost:5001
[15:04:15][INFO] |Microsoft.Hosting.Lifetime| - Now listening on: http://localhost:5000
[15:04:15][INFO] |Microsoft.Hosting.Lifetime| - Application started. Press Ctrl+C to shut down.

Ability to change message styles

// You can choose in: LogStyle.Default, LogStyle.Minimalistic, LogStyle.OneColor and LogStyle.Gray
LoggerConfiguration.LoggingStyle = LogStyle.Gray;

Configuring a database connection

LoggerConfiguration.DbConfig = new DatabaseConfiguration()
{
    DbType = DatabaseType.MySql,
    Database = "logger",
    Username = "root",
    Password = "",
    Host = "localhost",
    Port = 3306
};

The table will be created automatically (Database have to be clear!)

See also:

  • <a href="https://kimpiks.github.io/LoggerLib/">Documentation</a>

  • <a href="https://github.com/KimPiks/LoggerLib/blob/main/LICENSE.txt">License</a>

  • <a href="https://github.com/KimPiks/LoggerLib/blob/main/CONTRIBUTING.md">Contributing</a>

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.

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.2.2 619 4/14/2022
1.2.1 276 12/19/2021
1.2.0 274 12/19/2021
1.1.0 729 6/27/2021
1.0.3 305 3/22/2021
1.0.2 298 3/20/2021
1.0.1 325 3/8/2021
1.0.0 326 3/8/2021