Jinget.Logger 3.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Jinget.Logger --version 3.0.0
NuGet\Install-Package Jinget.Logger -Version 3.0.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="Jinget.Logger" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jinget.Logger --version 3.0.0
#r "nuget: Jinget.Logger, 3.0.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 Jinget.Logger as a Cake Addin
#addin nuget:?package=Jinget.Logger&version=3.0.0

// Install Jinget.Logger as a Cake Tool
#tool nuget:?package=Jinget.Logger&version=3.0.0

Jinget Logger

Using this library, you can easily save your application logs in Elasticsearch database or files.

How to Use:

Download the package from NuGet using Package Manager: Install-Package Jinget.Logger You can also use other methods supported by NuGet. Check Here for more information.

Configuration

Config logging destination:

Elasticsearch:

LogToElasticSearch: By calling this method, you are going to save your logs in Elasticsearch

builder.Host.LogToElasticSearch<OperationLog, ErrorLog, CustomLog>(blacklist);

blacklist: Log messages contain the blacklist array items will not logged.

After setting the logging destination, you need to configure Elasticsearch:

builder.Services.ConfigureElasticSearchLogger<OperationLog, ErrorLog, CustomLog>(
    new ElasticSearchSettingModel
    {
        UserName = <authentication username>,
        Password = <authentication password>,
        Url = <ElasticSearch Url>,
        UseSsl = <true|false>,
        RegisterDefaultLogModels = <true|false>,
        DiscoveryTypes = new List<Type> { typeof(OperationLog) }
    });

Url: Elasticsearch service url. If authentication is enabled, this address should not contains the PROTOCOL itself. Use 'abc.com' instead of 'http://abc.com'

UserName: Username, if authentication enabled on Elasticsearch service

Password: Password, if authentication enabled on Elasticsearch service

UseSsl: Use HTTP or HTTPS, if authentication enabled on Elasticsearch service.

RegisterDefaultLogModels: You can configure logging using your own models instead of OperationLog, ErrorLog or CustomLog. In order to do so, you can simple create derived types and use them instead of these types. When you are working with your own custom types, if you want to create index for default log models, you can set the RegisterDefaultLogModels property to true, otherwise you can set it as false.

DiscoveryTypes: Foreach type specified in this list, an index in Elasticsearch will be created

And finally you need to add the Jinget.Logger middleware to your pipeline:

app.UseJingetLogging();

Here is the complete configuration for a .NET 7.0 Web API application:

using Jinget.Core.Filters;
using Jinget.Logger.Configuration;
using Jinget.Logger.Entities.Log;

var builder = WebApplication.CreateBuilder(args);

var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build();

var blacklist = config.GetSection("logging:BlackList").Get<string[]>();
builder.Host.LogToElasticSearch<OperationLog, ErrorLog, CustomLog>(blacklist);

builder.Services.ConfigureElasticSearchLogger<OperationLog, ErrorLog, CustomLog>(
    new ElasticSearchSettingModel
    {
        UserName = "myuser",
        Password = "mypass",
        Url = "192.168.1.1:9200",
        UseSsl = false,
        RegisterDefaultLogModels = false,
        DiscoveryTypes = new List<Type> { typeof(OperationLog) }
    });
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();

app.UseJingetLogging();
app.MapControllers();
app.Run();

File:

LogToFile: By calling this method, you are going to save your logs in files

builder.Host.LogToFile(blacklist, fileNamePrefix: "Log-", logDirectory: "D:\\logs", 10, 15);

blacklist: Log messages contain the blacklist array items will not logged. FileNamePrefix: Gets or sets the filename prefix to use for log files. Defaults is logs- LogDirectory: The directory in which log files will be written, relative to the app process. Default is Logs directory. RetainedFileCountLimit: Gets or sets a strictly positive value representing the maximum retained file count or null for no limit. Defaults is 2 files. FileSizeLimit: Gets or sets a strictly positive value representing the maximum log size in MB or null for no limit. Once the log is full, no more messages will be appended. Defaults is 10MB.

After setting the logging destination, you need to configure Elasticsearch:

builder.Services.ConfigureFileLogger();

Here is the complete configuration for a .NET 7.0 Web API application:

using Jinget.Core.Filters;
using Jinget.Logger.Configuration;

var builder = WebApplication.CreateBuilder(args);

var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build();

var blacklist = config.GetSection("logging:BlackList").Get<string[]>();
builder.Host.LogToFile(blacklist, "Log-", "D:\\logs", 10, 15);
builder.Services.ConfigureFileLogger();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();

app.UseJingetLogging();

app.UseAuthorization();
app.MapControllers();
app.Run();

How to install

In order to install Jinget Logger please refer to nuget.org

Contact Me

👨‍💻 Twitter: https://twitter.com/_jinget

📧 Email: farahmandian2011@gmail.com

📣 Instagram: https://www.instagram.com/vahidfarahmandian

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
6.2.18-preview005 38 5/19/2024
6.2.18-preview004 34 5/19/2024
6.2.18-preview003 28 5/19/2024
6.2.18-preview002 27 5/19/2024
6.2.17 40 5/19/2024
6.2.16 35 5/18/2024
6.2.15 35 5/18/2024
6.2.14 34 5/18/2024
6.2.13 41 5/17/2024
6.2.12 47 5/17/2024
6.2.11 41 5/17/2024
6.2.10 44 5/17/2024
6.2.9 55 5/12/2024
6.2.8 64 5/9/2024
6.2.7 52 5/9/2024
6.2.6 78 5/7/2024
6.2.5 80 4/24/2024
6.2.4 156 2/1/2024
6.2.1 88 1/23/2024
6.2.0 78 1/23/2024
6.2.0-preview013 58 1/19/2024
6.2.0-preview012 55 1/19/2024
6.2.0-preview011 58 1/18/2024
6.2.0-preview010 62 1/14/2024
6.2.0-preview009 68 1/11/2024
6.2.0-preview008 70 1/1/2024
6.2.0-preview007 50 1/1/2024
6.2.0-preview006 59 1/1/2024
6.2.0-preview005 65 1/1/2024
6.2.0-preview001 85 12/30/2023
6.1.0 176 12/2/2023
6.1.0-preview003 89 12/2/2023
6.1.0-preview002 71 12/2/2023
6.1.0-preview001 89 12/2/2023
6.0.2 109 11/27/2023
6.0.1 118 11/22/2023
6.0.0 108 11/22/2023
3.5.0 133 10/28/2023
3.4.0 107 10/1/2023
3.3.1 118 9/30/2023
3.3.0 114 9/28/2023
3.2.5 117 9/28/2023
3.2.4 107 9/28/2023
3.2.3 113 9/28/2023
3.2.2 98 9/28/2023
3.2.1 97 9/28/2023
3.2.0 122 9/28/2023
3.1.0 106 9/27/2023
3.0.1 114 9/27/2023
3.0.0 124 9/14/2023
3.0.0-preview001 102 9/14/2023