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

// Install Jinget.Logger as a Cake Tool
#tool nuget:?package=Jinget.Logger&version=3.2.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.19-preview011 63 6/15/2024
6.2.19-preview010 54 6/14/2024
6.2.19-preview009 52 6/14/2024
6.2.19-preview008 53 6/13/2024
6.2.19-preview007 49 6/13/2024
6.2.19-preview006 47 6/13/2024
6.2.19-preview005 47 6/13/2024
6.2.19-preview004 48 6/13/2024
6.2.19-preview003 57 6/11/2024
6.2.19-preview002 56 6/8/2024
6.2.19-preview001 58 6/8/2024
6.2.18 74 6/6/2024
6.2.18-preview020 62 6/6/2024
6.2.18-preview019 64 6/6/2024
6.2.18-preview018 68 6/6/2024
6.2.18-preview017 64 6/2/2024
6.2.18-preview016 62 6/1/2024
6.2.18-preview015 68 5/28/2024
6.2.18-preview014 63 5/28/2024
6.2.18-preview013 63 5/28/2024
6.2.18-preview012 62 5/28/2024
6.2.18-preview011 64 5/26/2024
6.2.18-preview010 64 5/26/2024
6.2.18-preview009 67 5/26/2024
6.2.18-preview008 66 5/26/2024
6.2.18-preview007 82 5/22/2024
6.2.18-preview006 65 5/22/2024
6.2.18-preview005 78 5/19/2024
6.2.18-preview004 68 5/19/2024
6.2.18-preview003 71 5/19/2024
6.2.18-preview002 72 5/19/2024
6.2.17 87 5/19/2024
6.2.16 77 5/18/2024
6.2.15 82 5/18/2024
6.2.14 78 5/18/2024
6.2.13 83 5/17/2024
6.2.12 88 5/17/2024
6.2.11 81 5/17/2024
6.2.10 85 5/17/2024
6.2.9 65 5/12/2024
6.2.8 78 5/9/2024
6.2.7 64 5/9/2024
6.2.6 88 5/7/2024
6.2.5 86 4/24/2024
6.2.4 161 2/1/2024
6.2.1 93 1/23/2024
6.2.0 83 1/23/2024
6.2.0-preview013 64 1/19/2024
6.2.0-preview012 62 1/19/2024
6.2.0-preview011 63 1/18/2024
6.2.0-preview010 66 1/14/2024
6.2.0-preview009 75 1/11/2024
6.2.0-preview008 78 1/1/2024
6.2.0-preview007 55 1/1/2024
6.2.0-preview006 65 1/1/2024
6.2.0-preview005 70 1/1/2024
6.2.0-preview001 89 12/30/2023
6.1.0 182 12/2/2023
6.1.0-preview003 93 12/2/2023
6.1.0-preview002 74 12/2/2023
6.1.0-preview001 98 12/2/2023
6.0.2 114 11/27/2023
6.0.1 122 11/22/2023
6.0.0 115 11/22/2023
3.5.0 140 10/28/2023
3.4.0 112 10/1/2023
3.3.1 125 9/30/2023
3.3.0 126 9/28/2023
3.2.5 122 9/28/2023
3.2.4 110 9/28/2023
3.2.3 117 9/28/2023
3.2.2 102 9/28/2023
3.2.1 104 9/28/2023
3.2.0 127 9/28/2023
3.1.0 110 9/27/2023
3.0.1 119 9/27/2023
3.0.0 129 9/14/2023
3.0.0-preview001 108 9/14/2023