Jinget.Logger 8.0.0-preview012

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 8.0.0-preview012
                    
NuGet\Install-Package Jinget.Logger -Version 8.0.0-preview012
                    
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="8.0.0-preview012" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jinget.Logger" Version="8.0.0-preview012" />
                    
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 8.0.0-preview012
                    
#r "nuget: Jinget.Logger, 8.0.0-preview012"
                    
#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@8.0.0-preview012
                    
#: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=8.0.0-preview012&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Jinget.Logger&version=8.0.0-preview012&prerelease
                    
Install as a Cake Tool

Jinget Logger

Using this library, you can easily save your application logs in Elasticsearch database or files, by calling logger.Logxxx methods.

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

Log to Elasticsearch:

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

builder.Host.LogToElasticSearch(blacklist);

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

minAllowedLoglevel: Defines the minimum allowed log level. If log's severity is equal or greater than this value, then it will be saved in elasticsearch otherwise it will be ignored. If this parameter not set, then default log level will be applied(LogLevel.Information).

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

builder.Services.ConfigureElasticSearchLogger(
    new ElasticSearchSettingModel
    {
        CreateIndexPerPartition = <true|false>,
        UserName = <authentication username>,
        Password = <authentication password>,
        Url = <ElasticSearch Url>,
        UseSsl = <true|false>,
        UseGlobalExceptionHandler = <true|false>,
        Handle4xxResponses = <true|false>
    });

Url: Elasticsearch service url. This address should not contain the PROTOCOL itself. Use 'abc.com:9200' instead of 'http://abc.com:9200'

UserName: Username, if basic authentication enabled on Elasticsearch search service

Password: Password, if basic authentication enabled on Elasticsearch search service

UseSsl: Set whether to use SSL while connecting to Elasticsearch or not

CreateIndexPerPartition: Create index per partition using HttpContext.Items["jinget.log.partitionkey"] value. If this mode is selected, then index creation will be deferred until the first document insertion. foreach partition key, a separated index will be created. all the indexes will share the same data model.

RefreshType: In Elasticsearch, the Index, Update, Delete, and Bulk APIs support setting refresh to control when changes made by this request are made visible to search.

UseGlobalExceptionHandler: If set to true then global exception handler will be used which in turn will be rewrite the exception response output.

Handle4xxResponses: If set to true then http request exception handler will be used which in turn will be handle the 4xx responses.

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) =>
    {
        //define the partitioning logic
        bool partitionKeyExists = context.Request.Headers.TryGetValue("jinget.client_id", out StringValues partitionKey);
        if (partitionKeyExists)
            context.SetPartitionKey($"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 exist in the request, the default index name will be used which are created using the following code:

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

When using partition key, index names will be constructed as below:

$"{AppDomain.CurrentDomain.FriendlyName.ToLower()}-{partitionKey.ToLower()}"

Here is the complete configuration for a .NET 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(blacklist);

var elasticSearchSetting = new ElasticSearchSettingModel
{
    UserName = "myuser",
    Password = "mypass",
    Url = "192.168.1.1:9200",
    UseSsl = false,
    UseGlobalExceptionHandler = true,
    Handle4xxResponses = false
};
builder.Services.ConfigureElasticSearchLogger(elasticSearchSetting);

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

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.SetPartitionKey($"test.{partitionKey}");

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

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

Note: While logging data you might need to filter the request/response headers. In order to achieve this, you can use BlackListHeader or WhiteListHeader classes. If Both of these classes used, then only BlackListHeader will be applied. To make use of these classes you can add them to DI container like below: for black listed headers:(headers which you do NOT want to log)

builder.Services.Configure<BlackListHeader>(x => x.Headers = ["header1","header2"]);

Or for white listed headers:(headers which you want to log them ONLY)

builder.Services.Configure<WhiteListHeader>(x => x.Headers = ["header1","header2"]);

Log to File:

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

FileSettingModel fileSetting = new FileSettingModel
{
    FileNamePrefix = "Log-",
    LogDirectory = "D:\\Logs",
    RetainFileCountLimit = 5,
    FileSizeLimitMB = 10,
    UseGlobalExceptionHandler = true,
    Handle4xxResponses = true,
};
builder.Host.LogToFile(blacklist, fileSetting);

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

minAllowedLoglevel: Defines the minimum allowed log level. Default log level is LogLevel.Information.

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 file logger:

builder.Services.ConfigureFileLogger(fileSetting);

Here is the complete configuration for a .NET 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[]>();
FileSettingModel fileSetting = new FileSettingModel
{
    FileNamePrefix = "Log",
    LogDirectory = "Logs",
    RetainFileCountLimit = 5,
    FileSizeLimitMB = 10,
    UseGlobalExceptionHandler = true,
    Handle4xxResponses = true,
};
builder.Host.LogToFile(blacklist, fileSetting);
builder.Services.ConfigureFileLogger(fileSetting);

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 net8.0 is compatible.  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.50 64 9/11/2025
8.0.49 99 9/8/2025
8.0.48 90 9/8/2025
8.0.47 93 9/7/2025
8.0.46 84 8/22/2025
8.0.45 137 7/31/2025
8.0.44 118 7/31/2025
8.0.43 117 7/30/2025
8.0.42 121 7/30/2025
8.0.41 120 7/30/2025
8.0.40 115 7/30/2025
8.0.39 110 7/29/2025
8.0.38 98 7/28/2025
8.0.37 101 7/28/2025
8.0.36 108 7/28/2025
8.0.36-preview005 110 7/27/2025
8.0.35 83 7/19/2025
8.0.34 78 7/18/2025
8.0.33 160 6/29/2025
8.0.32 145 6/29/2025
8.0.31 100 6/28/2025
8.0.30 64 6/27/2025
8.0.29 75 6/27/2025
8.0.28 77 6/27/2025
8.0.27 106 6/27/2025
8.0.26 118 6/21/2025
8.0.25 160 6/15/2025
8.0.25-preview001 145 6/15/2025
8.0.24 149 5/31/2025
8.0.23 160 5/28/2025
8.0.23-preview001 148 5/28/2025
8.0.22 170 5/25/2025
8.0.21 180 5/11/2025
8.0.20 156 5/11/2025
8.0.19 155 5/11/2025
8.0.18 190 4/21/2025
8.0.17 185 4/21/2025
8.0.16 119 4/19/2025
8.0.15 223 4/13/2025
8.0.14 188 4/7/2025
8.0.13 176 4/7/2025
8.0.12 122 4/5/2025
8.0.11 227 3/9/2025
8.0.10 204 3/9/2025
8.0.9 209 3/9/2025
8.0.8 175 2/27/2025
8.0.7 131 2/27/2025
8.0.6 135 2/27/2025
8.0.5 136 2/26/2025
8.0.4 147 2/25/2025
8.0.3 133 2/24/2025
8.0.2 125 2/24/2025
8.0.1 161 2/20/2025
8.0.0 187 1/22/2025
8.0.0-preview013 217 12/19/2024
8.0.0-preview012 113 12/19/2024
8.0.0-preview011 111 12/17/2024
8.0.0-preview010 124 12/16/2024
8.0.0-preview009 107 12/15/2024
8.0.0-preview008 119 11/25/2024
8.0.0-preview007 157 11/11/2024
8.0.0-preview006 140 11/2/2024
8.0.0-preview005 107 11/2/2024
8.0.0-preview004 112 11/1/2024
8.0.0-preview003 120 11/1/2024
8.0.0-preview002 103 11/1/2024
8.0.0-preview001 102 11/1/2024
6.2.23-preview003 110 10/31/2024
6.2.23-preview002 106 10/31/2024
6.2.22 155 10/26/2024
6.2.21 133 10/26/2024
6.2.20 134 10/26/2024
6.2.19-preview037 108 10/14/2024
6.2.19-preview036 105 9/30/2024
6.2.19-preview035 128 9/10/2024
6.2.19-preview034 121 9/9/2024
6.2.19-preview033 125 9/1/2024
6.2.19-preview032 130 9/1/2024
6.2.19-preview031 123 8/31/2024
6.2.19-preview029 123 8/26/2024
6.2.19-preview028 137 8/26/2024
6.2.19-preview027 153 8/26/2024
6.2.19-preview026 150 8/21/2024
6.2.19-preview025 143 8/21/2024
6.2.19-preview024 138 8/19/2024
6.2.19-preview023 121 8/8/2024
6.2.19-preview022 134 8/8/2024
6.2.19-preview021 113 8/5/2024
6.2.19-preview020 99 8/5/2024
6.2.19-preview019 115 8/5/2024
6.2.19-preview018 86 8/3/2024
6.2.19-preview017 106 7/30/2024
6.2.19-preview016 107 7/29/2024
6.2.19-preview015 109 7/29/2024
6.2.19-preview014 119 7/26/2024
6.2.19-preview013 123 7/20/2024
6.2.19-preview012 112 7/20/2024
6.2.19-preview011 134 6/15/2024
6.2.19-preview010 123 6/14/2024
6.2.19-preview009 120 6/14/2024
6.2.19-preview008 120 6/13/2024
6.2.19-preview007 120 6/13/2024
6.2.19-preview006 122 6/13/2024
6.2.19-preview005 116 6/13/2024
6.2.19-preview004 121 6/13/2024
6.2.19-preview003 126 6/11/2024
6.2.19-preview002 124 6/8/2024
6.2.19-preview001 127 6/8/2024
6.2.18 178 6/6/2024
6.2.18-preview020 128 6/6/2024
6.2.18-preview019 132 6/6/2024
6.2.18-preview018 140 6/6/2024
6.2.18-preview017 132 6/2/2024
6.2.18-preview016 132 6/1/2024
6.2.18-preview015 138 5/28/2024
6.2.18-preview014 134 5/28/2024
6.2.18-preview013 133 5/28/2024
6.2.18-preview012 130 5/28/2024
6.2.18-preview011 139 5/26/2024
6.2.18-preview010 129 5/26/2024
6.2.18-preview009 136 5/26/2024
6.2.18-preview008 140 5/26/2024
6.2.18-preview007 154 5/22/2024
6.2.18-preview006 127 5/22/2024
6.2.18-preview005 147 5/19/2024
6.2.18-preview004 133 5/19/2024
6.2.18-preview003 133 5/19/2024
6.2.18-preview002 134 5/19/2024
6.2.17 168 5/19/2024
6.2.16 168 5/18/2024
6.2.15 171 5/18/2024
6.2.14 169 5/18/2024
6.2.13 168 5/17/2024
6.2.12 170 5/17/2024
6.2.11 173 5/17/2024
6.2.10 168 5/17/2024
6.2.9 145 5/12/2024
6.2.8 165 5/9/2024
6.2.7 156 5/9/2024
6.2.6 163 5/7/2024
6.2.5 169 4/24/2024
6.2.4 252 2/1/2024
6.2.1 176 1/23/2024
6.2.0 167 1/23/2024
6.2.0-preview013 129 1/19/2024
6.2.0-preview012 124 1/19/2024
6.2.0-preview011 124 1/18/2024
6.2.0-preview010 134 1/14/2024
6.2.0-preview009 133 1/11/2024
6.2.0-preview008 141 1/1/2024
6.2.0-preview007 119 1/1/2024
6.2.0-preview006 131 1/1/2024
6.2.0-preview005 139 1/1/2024
6.2.0-preview001 155 12/30/2023
6.1.0 257 12/2/2023
6.1.0-preview003 163 12/2/2023
6.1.0-preview002 137 12/2/2023
6.1.0-preview001 156 12/2/2023
6.0.2 183 11/27/2023
6.0.1 185 11/22/2023
6.0.0 181 11/22/2023
3.5.0 219 10/28/2023
3.4.0 191 10/1/2023
3.3.1 208 9/30/2023
3.3.0 199 9/28/2023
3.2.5 200 9/28/2023
3.2.4 180 9/28/2023
3.2.3 189 9/28/2023
3.2.2 186 9/28/2023
3.2.1 180 9/28/2023
3.2.0 213 9/28/2023
3.1.0 194 9/27/2023
3.0.1 198 9/27/2023
3.0.0 205 9/14/2023
3.0.0-preview001 181 9/14/2023