LoggerLib 1.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package LoggerLib --version 1.2.0
NuGet\Install-Package LoggerLib -Version 1.2.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="LoggerLib" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LoggerLib --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LoggerLib, 1.2.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 LoggerLib as a Cake Addin
#addin nuget:?package=LoggerLib&version=1.2.0
// Install LoggerLib as a Cake Tool
#tool nuget:?package=LoggerLib&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
General info
Logger for your C# project
Saving logs to the console and to the .log
or .txt
files.
You can also save logs to the database (currently only MySQL is supported).
Old files are backed up to reduce the size of the logs.
Installation
PM> Install-Package LoggerLib -Version 1.2.0
or
> dotnet add package LoggerLib --version 1.2.0
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 https://github.com/K1mP1x/LoggerLib/tree/main/Example 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()
{
Database = "logger",
Username = "root",
Password = "",
Host = "localhost",
Port = 3306
};
The table will be created automatically
See also:
Product | Versions 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
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- MySqlConnector (>= 2.1.0)
- Pomelo.EntityFrameworkCore.MySql (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.