![]() |
VOOZH | about |
dotnet add package CG.Infrastructure.Logging --version 3.10.5
NuGet\Install-Package CG.Infrastructure.Logging -Version 3.10.5
<PackageReference Include="CG.Infrastructure.Logging" Version="3.10.5" />
<PackageVersion Include="CG.Infrastructure.Logging" Version="3.10.5" />Directory.Packages.props
<PackageReference Include="CG.Infrastructure.Logging" />Project file
paket add CG.Infrastructure.Logging --version 3.10.5
#r "nuget: CG.Infrastructure.Logging, 3.10.5"
#:package CG.Infrastructure.Logging@3.10.5
#addin nuget:?package=CG.Infrastructure.Logging&version=3.10.5Install as a Cake Addin
#tool nuget:?package=CG.Infrastructure.Logging&version=3.10.5Install as a Cake Tool
A comprehensive logging library for .NET applications built on top of Serilog, providing structured logging capabilities with extensive configuration options and multiple output sinks.
CG.Infrastructure.Logging is a .NET 10.0 library that simplifies logging implementation across your applications. It provides a unified logging interface with Serilog as the underlying engine, offering structured logging, correlation ID tracking, and multiple output destinations. This library works in conjunction with CG.Infrastructure.Logging.Data for database schema management and query definitions.
dotnet add package CG.Infrastructure.Logging
// Program.cs or Startup.cs
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Configure Serilog
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("logs/app-.txt", rollingInterval: RollingInterval.Day));
{
"Serilog": {
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "logs/app-.txt",
"rollingInterval": "Day",
"retainedFileCountLimit": 7
}
}
],
"Enrich": ["FromLogContext", "WithCorrelationId", "WithEnvironment", "WithProcess", "WithThread"]
}
}
using Serilog;
public class ExampleService
{
private readonly ILogger _logger;
public ExampleService(ILogger logger)
{
_logger = logger;
}
public void ProcessData(string data)
{
_logger.Information("Processing data: {Data}", data);
try
{
// Process data
_logger.Information("Data processed successfully");
}
catch (Exception ex)
{
_logger.Error(ex, "Error processing data: {Data}", data);
throw;
}
}
}
_logger.Information("User {UserId} accessed {Resource} from {IPAddress}",
userId, resourceName, ipAddress);
// Automatically included when using Serilog.Enrichers.CorrelationId
_logger.Information("Request processed");
// Output: [CorrelationId: abc123] Request processed
{
"Serilog": {
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "RequestPath like '/health%'"
}
}
]
}
}
{
"Serilog": {
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Server=...;Database=Logs;...",
"tableName": "LogEvents",
"schemaName": "Logging",
"autoCreateSqlTable": false
}
}
]
}
}
Note: For production environments, it's recommended to use the Infrastructure.Logging.Data project with DbUp for database schema management rather than auto-creating tables.
{
"Serilog": {
"WriteTo": [
{
"Name": "Http",
"Args": {
"requestUri": "https://logs.example.com/api/logs",
"queueLimitBytes": null
}
}
]
}
}
Infrastructure.Logging.Data with DbUp for production database setupThis project is part of the CG Infrastructure Libraries. For contributions, please refer to the main infrastructure repository guidelines.
See the LICENSE file in the root directory for licensing information.
For issues and questions related to this library, please contact the development team or create an issue in the project repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on CG.Infrastructure.Logging:
| Package | Downloads |
|---|---|
|
CG.Platform.ViewModels
Platform view models library with shared services |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.10.5 | 129 | 4/1/2026 |
| 3.10.4 | 253 | 8/15/2025 |
| 3.10.3 | 266 | 8/10/2025 |
| 3.10.2 | 239 | 7/11/2025 |
| 3.10.1 | 263 | 6/18/2025 |
| 3.10.0 | 241 | 6/7/2025 |
| 3.9.0 | 261 | 12/10/2024 |
| 3.0.5 | 267 | 7/12/2024 |
| 3.0.4 | 306 | 3/19/2024 |
| 3.0.3 | 277 | 3/19/2024 |
| 3.0.2 | 259 | 3/19/2024 |
| 3.0.1 | 265 | 2/26/2024 |
| 3.0.0 | 295 | 2/19/2024 |
| 2.0.0 | 467 | 5/15/2023 |
| 1.0.2 | 730 | 5/27/2022 |
| 1.0.1 | 701 | 5/27/2022 |
| 1.0.0 | 707 | 5/26/2022 |