CSharpEssentials.LoggerHelper
1.1.1
See the version list below for details.
dotnet add package CSharpEssentials.LoggerHelper --version 1.1.1
NuGet\Install-Package CSharpEssentials.LoggerHelper -Version 1.1.1
<PackageReference Include="CSharpEssentials.LoggerHelper" Version="1.1.1" />
<PackageVersion Include="CSharpEssentials.LoggerHelper" Version="1.1.1" />
<PackageReference Include="CSharpEssentials.LoggerHelper" />
paket add CSharpEssentials.LoggerHelper --version 1.1.1
#r "nuget: CSharpEssentials.LoggerHelper, 1.1.1"
#:package CSharpEssentials.LoggerHelper@1.1.1
#addin nuget:?package=CSharpEssentials.LoggerHelper&version=1.1.1
#tool nuget:?package=CSharpEssentials.LoggerHelper&version=1.1.1
CSharpEssentials.LoggerHelper
A flexible and powerful logging library for .NET applications that simplifies the implementation of structured logging with multiple sink options.
Features
- Multi-sink logging support:
- SQL Server
- PostgreSQL
- Console
- File
- Elasticsearch
- Telegram
- Conditional logging based on log levels
- Structured logging with custom properties
- Asynchronous and synchronous logging methods
- Machine name, transaction ID, and action tracking
- JSON configuration support
Installation
dotnet add package CSharpEssentials.LoggerHelper
Configuration
Create an appsettings.LoggerHelper.json
file in your project root with the following structure:
{
"Serilog": {
"SerilogConfiguration": {
"SerilogCondition": [
{
"Sink": "Console",
"Level": ["Information", "Warning", "Error", "Fatal"]
},
{
"Sink": "File",
"Level": ["Error", "Fatal"]
},
{
"Sink": "PostgreSQL",
"Level": ["Error", "Fatal"]
},
{
"Sink": "MSSqlServer",
"Level": ["Error", "Fatal"]
},
{
"Sink": "Telegram",
"Level": ["Fatal"]
}
],
"SerilogOption": {
"PostgreSQL": {
"connectionstring": "Host=localhost;Database=logs;Username=postgres;Password=yourpassword"
},
"MSSqlServer": {
"connectionString": "Server=localhost;Database=Logs;Trusted_Connection=True;",
"sinkOptionsSection": {
"tableName": "Logs",
"schemaName": "dbo",
"autoCreateSqlTable": true,
"batchPostingLimit": 50,
"period": "00:00:30"
}
},
"TelegramOption": {
"Api_Key": "your-telegram-bot-api-key",
"chatId": "your-chat-id"
},
"File": {
"Path": "logs"
},
"GeneralConfig": {
"EnableSelfLogging": false
}
}
}
}
}
Setup in ASP.NET Core Application
Register the logger in your Program.cs
:
using CSharpEssentials.LoggerHelper;
var builder = WebApplication.CreateBuilder(args);
// Add logger configuration
builder.Services.addloggerConfiguration(builder);
// ... other services
var app = builder.Build();
// ... configure app
app.Run();
Usage
First, implement the IRequest
interface in your request model:
public class MyRequest : IRequest
{
public string IdTransaction { get; set; } = Guid.NewGuid().ToString();
public string Action { get; set; } = "YourActionName";
// Other properties
}
Then use the logger in your code:
using CSharpEssentials.LoggerHelper;
using Serilog.Events;
// For synchronous logging
var request = new MyRequest();
loggerExtension<MyRequest>.TraceSync(
request,
LogEventLevel.Information,
null,
"Operation completed successfully: {OperationName}",
"CreateUser"
);
// For asynchronous logging
await Task.Run(() => loggerExtension<MyRequest>.TraceAsync(
request,
LogEventLevel.Error,
exception,
"Error during operation: {OperationName}",
"UpdateUser"
));
// For logging without a request object
loggerExtension<IRequest>.TraceSync(
null,
LogEventLevel.Warning,
null,
"System warning: {WarningMessage}",
"Low disk space"
);
Log Parameters
The TraceSync
and TraceAsync
methods accept the following parameters:
- request: An object implementing
IRequest
(contains IdTransaction and Action) - level: Log severity level (Debug, Information, Warning, Error, Fatal)
- ex: Exception object (can be null)
- message: Log message with optional placeholders for variables
- args: Additional parameters to be inserted into message placeholders
Database Schema
PostgreSQL
The logger creates a table with the following columns:
- timestamp
- level
- message
- exception
- properties
- IdTransaction
- MachineName
- Action
SQL Server
The logger creates a table with the following columns:
- LogEvent (JSON)
- IdTransaction
- MachineName
- Action
License
Author
Alessandro Chiodo
Version
Current version: 1.0.1
Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore (>= 2.3.0)
- Microsoft.Extensions.Configuration (>= 9.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.1)
- Microsoft.Extensions.Configuration.Json (>= 9.0.1)
- Serilog (>= 4.2.0)
- Serilog.Settings.Configuration (>= 9.0.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- Serilog.Sinks.Email (>= 4.0.0)
- Serilog.Sinks.MSSqlServer (>= 8.1.0)
- Serilog.Sinks.Postgresql.Alternative (>= 4.1.3)
- Serilog.Sinks.Telegram.Alternative (>= 1.4.3)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on CSharpEssentials.LoggerHelper:
Package | Downloads |
---|---|
CSharpEssentials.LoggerHelper.Sink.MSSqlServer
A powerful SQL Server sink for CSharpEssentials.LoggerHelper , designed to log directly into Microsoft SQL Server with automatic table creation, custom columns, and structured context properties. |
|
CSharpEssentials.LoggerHelper.Sink.Elasticsearch
A high-performance Elasticsearch sink for CSharpEssentials.LoggerHelper , designed to index logs into Elasticsearch for fast search, advanced filtering, and real-time dashboards with Kibana. |
|
CSharpEssentials.LoggerHelper.Sink.File
Sink File for package LoggerHelper |
|
CSharpEssentials.LoggerHelper.Sink.Postgresql
Stores structured logs directly into PostgreSQL with support for custom schemas, JSON fields, and automatic table creation for deep analytics and long-term storage. |
|
CSharpEssentials.LoggerHelper.Sink.Console
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
4.0.3 | 8 | 9/14/2025 |
4.0.2 | 115 | 9/11/2025 |
4.0.1.1 | 107 | 9/11/2025 |
4.0.1 | 113 | 9/11/2025 |
4.0.0 | 320 | 8/25/2025 |
3.1.6 | 235 | 8/5/2025 |
3.1.5 | 283 | 6/15/2025 |
3.1.4 | 362 | 6/12/2025 |
3.1.3 | 291 | 6/11/2025 |
3.1.2 | 212 | 6/9/2025 |
3.1.1 | 410 | 6/8/2025 |
3.1.0 | 198 | 6/8/2025 |
3.0.6 | 150 | 6/5/2025 |
3.0.5 | 152 | 6/5/2025 |
3.0.4 | 144 | 6/2/2025 |
3.0.3 | 147 | 6/2/2025 |
3.0.2 | 358 | 6/1/2025 |
3.0.1 | 145 | 5/30/2025 |
3.0.0 | 158 | 5/30/2025 |
2.0.9 | 79 | 5/24/2025 |
2.0.8 | 114 | 5/23/2025 |
2.0.7 | 116 | 5/23/2025 |
2.0.6 | 142 | 5/19/2025 |
2.0.5 | 230 | 5/14/2025 |
2.0.4 | 258 | 5/13/2025 |
2.0.1 | 136 | 5/11/2025 |
2.0.0 | 140 | 5/11/2025 |
1.3.1 | 141 | 5/11/2025 |
1.2.3 | 91 | 5/10/2025 |
1.2.2 | 74 | 5/10/2025 |
1.2.1 | 119 | 5/9/2025 |
1.1.6 | 147 | 5/6/2025 |
1.1.5 | 171 | 5/5/2025 |
1.1.4 | 153 | 5/4/2025 |
1.1.3 | 167 | 5/4/2025 |
1.1.2 | 159 | 5/4/2025 |
1.1.1 | 150 | 5/4/2025 |
1.0.1 | 123 | 2/19/2025 |
1.0.0 | 111 | 2/19/2025 |