Jinget.Logger 6.2.0-preview013

Prefix Reserved
This is a prerelease version of Jinget.Logger.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Jinget.Logger --version 6.2.0-preview013
                    
NuGet\Install-Package Jinget.Logger -Version 6.2.0-preview013
                    
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="6.2.0-preview013" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jinget.Logger" Version="6.2.0-preview013" />
                    
Directory.Packages.props
<PackageReference Include="Jinget.Logger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Jinget.Logger --version 6.2.0-preview013
                    
#r "nuget: Jinget.Logger, 6.2.0-preview013"
                    
#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.
#:package Jinget.Logger@6.2.0-preview013
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Jinget.Logger&version=6.2.0-preview013&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Jinget.Logger&version=6.2.0-preview013&prerelease
                    
Install as a Cake Tool

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

CreateIndexPerPartition: Create index per partition using HttpContext.Items["jinget.log.partitionkey"] value. If this mode is selected, then RegisterDefaultLogModels and also DiscoveryTypes will not be used. If this mode is selected, then index creation will be deferred until the first document insertion. foeach partition key, a separated index will be created. all of the indexes will share the same data model. for request/response logs, Entities.Log.OperationLog will be used. for errors, Entities.Log.ErrorLog will be used. for custom logs, Entities.Log.CustomLog will be used.

If you want to use partition key, instead of predefined/custom models, then you do not need to pass the generic types. Just like below:

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

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

app.UseJingetLogging();

If you are using partition key, then you need to set your partition key before calling app.UseJingetLogging(). LIke below:

app.UseWhen(p => elasticSearchSetting.CreateIndexPerPartition, appBuilder =>
{
    appBuilder.Use(async (context, next) =>
    {
        bool partitionKeyExists = context.Request.Headers.TryGetValue("jinget.client_id", out StringValues partitionKey);

        if (partitionKeyExists)
            context.Items.Add("jinget.log.partitionkey", $"test.{partitionKey}");

        await next.Invoke();
    });
});

For example in the above code, logs will be partitioned based on the jinget.client_id header's value. If this header does not exists in the request, the default index name will be used which are created using the following code:

$"{AppDomain.CurrentDomain.FriendlyName}.{typeof(TModelType).Name}".ToLower();

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

Without Partitioning:

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();

With Partitioning:

using Jinget.Core.Filters;
using Jinget.Logger.Configuration;
using Jinget.Logger.Configuration.Middlewares.ElasticSearch;
using Jinget.Logger.Entities.Log;
using Jinget.Logger.Handlers.CommandHandlers;
using Microsoft.Extensions.Primitives;

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(blacklist);
builder.Services.ConfigureElasticSearchLogger(
    new ElasticSearchSettingModel
    {
        CreateIndexPerPartition = true,
        UserName = "myuser",
        Password = "mypass",
        Url = "192.168.1.1:9200",
        UseSsl = false
    });
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();

app.UseWhen(p => elasticSearchSetting.CreateIndexPerPartition, appBuilder =>
{
    appBuilder.Use(async (context, next) =>
    {
        bool partitionKeyExists = context.Request.Headers.TryGetValue("jinget.client_id", out StringValues partitionKey);

        if (partitionKeyExists)
            context.Items.Add("jinget.log.partitionkey", $"test.{partitionKey}");

        await next.Invoke();
    });
});

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
8.0.46 61 8/22/2025
8.0.45 134 7/31/2025
8.0.44 113 7/31/2025
8.0.43 112 7/30/2025
8.0.42 116 7/30/2025
8.0.41 117 7/30/2025
8.0.40 112 7/30/2025
8.0.39 106 7/29/2025
8.0.38 95 7/28/2025
8.0.37 98 7/28/2025
8.0.36 104 7/28/2025
8.0.36-preview005 106 7/27/2025
8.0.35 36 7/19/2025
8.0.34 33 7/18/2025
8.0.33 157 6/29/2025
8.0.32 142 6/29/2025
8.0.31 97 6/28/2025
8.0.30 61 6/27/2025
8.0.29 72 6/27/2025
8.0.28 73 6/27/2025
8.0.27 102 6/27/2025
8.0.26 114 6/21/2025
8.0.25 157 6/15/2025
8.0.25-preview001 142 6/15/2025
8.0.24 141 5/31/2025
8.0.23 158 5/28/2025
8.0.23-preview001 145 5/28/2025
8.0.22 169 5/25/2025
8.0.21 179 5/11/2025
8.0.20 154 5/11/2025
8.0.19 153 5/11/2025
8.0.18 188 4/21/2025
8.0.17 183 4/21/2025
8.0.16 117 4/19/2025
8.0.15 222 4/13/2025
8.0.14 187 4/7/2025
8.0.13 175 4/7/2025
8.0.12 121 4/5/2025
8.0.11 224 3/9/2025
8.0.10 199 3/9/2025
8.0.9 206 3/9/2025
8.0.8 172 2/27/2025
8.0.7 130 2/27/2025
8.0.6 133 2/27/2025
8.0.5 134 2/26/2025
8.0.4 146 2/25/2025
8.0.3 132 2/24/2025
8.0.2 123 2/24/2025
8.0.1 159 2/20/2025
8.0.0 185 1/22/2025
8.0.0-preview013 215 12/19/2024
8.0.0-preview012 112 12/19/2024
8.0.0-preview011 109 12/17/2024
8.0.0-preview010 122 12/16/2024
8.0.0-preview009 106 12/15/2024
8.0.0-preview008 118 11/25/2024
8.0.0-preview007 156 11/11/2024
8.0.0-preview006 138 11/2/2024
8.0.0-preview005 104 11/2/2024
8.0.0-preview004 110 11/1/2024
8.0.0-preview003 119 11/1/2024
8.0.0-preview002 101 11/1/2024
8.0.0-preview001 100 11/1/2024
6.2.23-preview003 108 10/31/2024
6.2.23-preview002 104 10/31/2024
6.2.22 154 10/26/2024
6.2.21 131 10/26/2024
6.2.20 131 10/26/2024
6.2.19-preview037 106 10/14/2024
6.2.19-preview036 102 9/30/2024
6.2.19-preview035 126 9/10/2024
6.2.19-preview034 119 9/9/2024
6.2.19-preview033 124 9/1/2024
6.2.19-preview032 128 9/1/2024
6.2.19-preview031 122 8/31/2024
6.2.19-preview029 122 8/26/2024
6.2.19-preview028 135 8/26/2024
6.2.19-preview027 152 8/26/2024
6.2.19-preview026 148 8/21/2024
6.2.19-preview025 142 8/21/2024
6.2.19-preview024 136 8/19/2024
6.2.19-preview023 120 8/8/2024
6.2.19-preview022 131 8/8/2024
6.2.19-preview021 112 8/5/2024
6.2.19-preview020 97 8/5/2024
6.2.19-preview019 112 8/5/2024
6.2.19-preview018 83 8/3/2024
6.2.19-preview017 104 7/30/2024
6.2.19-preview016 106 7/29/2024
6.2.19-preview015 108 7/29/2024
6.2.19-preview014 118 7/26/2024
6.2.19-preview013 123 7/20/2024
6.2.19-preview012 111 7/20/2024
6.2.19-preview011 133 6/15/2024
6.2.19-preview010 119 6/14/2024
6.2.19-preview009 117 6/14/2024
6.2.19-preview008 118 6/13/2024
6.2.19-preview007 119 6/13/2024
6.2.19-preview006 120 6/13/2024
6.2.19-preview005 114 6/13/2024
6.2.19-preview004 119 6/13/2024
6.2.19-preview003 125 6/11/2024
6.2.19-preview002 123 6/8/2024
6.2.19-preview001 126 6/8/2024
6.2.18 177 6/6/2024
6.2.18-preview020 127 6/6/2024
6.2.18-preview019 130 6/6/2024
6.2.18-preview018 138 6/6/2024
6.2.18-preview017 130 6/2/2024
6.2.18-preview016 131 6/1/2024
6.2.18-preview015 136 5/28/2024
6.2.18-preview014 132 5/28/2024
6.2.18-preview013 131 5/28/2024
6.2.18-preview012 129 5/28/2024
6.2.18-preview011 136 5/26/2024
6.2.18-preview010 128 5/26/2024
6.2.18-preview009 133 5/26/2024
6.2.18-preview008 139 5/26/2024
6.2.18-preview007 153 5/22/2024
6.2.18-preview006 126 5/22/2024
6.2.18-preview005 146 5/19/2024
6.2.18-preview004 131 5/19/2024
6.2.18-preview003 131 5/19/2024
6.2.18-preview002 133 5/19/2024
6.2.17 168 5/19/2024
6.2.16 167 5/18/2024
6.2.15 169 5/18/2024
6.2.14 167 5/18/2024
6.2.13 167 5/17/2024
6.2.12 166 5/17/2024
6.2.11 172 5/17/2024
6.2.10 164 5/17/2024
6.2.9 143 5/12/2024
6.2.8 163 5/9/2024
6.2.7 154 5/9/2024
6.2.6 160 5/7/2024
6.2.5 167 4/24/2024
6.2.4 250 2/1/2024
6.2.1 174 1/23/2024
6.2.0 164 1/23/2024
6.2.0-preview013 128 1/19/2024
6.2.0-preview012 123 1/19/2024
6.2.0-preview011 122 1/18/2024
6.2.0-preview010 130 1/14/2024
6.2.0-preview009 132 1/11/2024
6.2.0-preview008 138 1/1/2024
6.2.0-preview007 118 1/1/2024
6.2.0-preview006 129 1/1/2024
6.2.0-preview005 137 1/1/2024
6.2.0-preview001 154 12/30/2023
6.1.0 255 12/2/2023
6.1.0-preview003 161 12/2/2023
6.1.0-preview002 135 12/2/2023
6.1.0-preview001 155 12/2/2023
6.0.2 182 11/27/2023
6.0.1 184 11/22/2023
6.0.0 180 11/22/2023
3.5.0 216 10/28/2023
3.4.0 190 10/1/2023
3.3.1 207 9/30/2023
3.3.0 197 9/28/2023
3.2.5 198 9/28/2023
3.2.4 178 9/28/2023
3.2.3 187 9/28/2023
3.2.2 183 9/28/2023
3.2.1 178 9/28/2023
3.2.0 210 9/28/2023
3.1.0 190 9/27/2023
3.0.1 196 9/27/2023
3.0.0 204 9/14/2023
3.0.0-preview001 178 9/14/2023