Netrilo.Infrastructure.Common.Logging
1.0.4
dotnet add package Netrilo.Infrastructure.Common.Logging --version 1.0.4
NuGet\Install-Package Netrilo.Infrastructure.Common.Logging -Version 1.0.4
<PackageReference Include="Netrilo.Infrastructure.Common.Logging" Version="1.0.4" />
<PackageVersion Include="Netrilo.Infrastructure.Common.Logging" Version="1.0.4" />
<PackageReference Include="Netrilo.Infrastructure.Common.Logging" />
paket add Netrilo.Infrastructure.Common.Logging --version 1.0.4
#r "nuget: Netrilo.Infrastructure.Common.Logging, 1.0.4"
#:package Netrilo.Infrastructure.Common.Logging@1.0.4
#addin nuget:?package=Netrilo.Infrastructure.Common.Logging&version=1.0.4
#tool nuget:?package=Netrilo.Infrastructure.Common.Logging&version=1.0.4
Netrilo.Infrastructure.Common.Logging
Part of the Netrilo.Infrastructure SDK
π¦ NuGet
π Overview
Netrilo.Infrastructure.Common.Logging provides logging extensions for .NET applications using Serilog and optional Elastic APM integration.
It is designed to simplify the setup of structured logging, log enrichment, and distributed tracing in ASP.NET Core applications.
β¨ Features
β Preconfigured Serilog logger:
- Enrich logs with context properties.
- Enrich logs with exception details.
- Add correlation ID from request headers.
- Filter out noisy Swagger logs.
- Load configuration directly from
appsettings.json/ environment.
β Seamless integration with ASP.NET Core logging.
β Built-in Elastic APM setup with one line of code.
β Extension methods for easy usage.
π Installation
If available on NuGet:
dotnet add package Netrilo.Infrastructure.Common.Logging
Or add a reference to your project.
π Usage
1. Configure Serilog Logger
using Netrilo.Infrastructure.Common.Logging.Serilog;
var logger = LoggingExtensions.AddLogging(Configuration);
This will:
- Enrich logs with context and exceptions.
- Add correlation IDs for request tracing.
- Exclude Swagger logs.
- Load settings from your
appsettings.json.
2. Add Elastic APM
using Netrilo.Infrastructure.Common.Logging.Serilog;
builder.Services.AddApm();
This will integrate Elastic APM for distributed tracing and performance monitoring.
3. Hook Into ASP.NET Core Pipeline
using Netrilo.Infrastructure.Common.Logging.Serilog;
var app = builder.Build();
// Attach Serilog to ASP.NET Coreβs logging pipeline
app.UseLogging(builder.Configuration, app.LoggerFactory);
app.Run();
βοΈ Example appsettings.json
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Elasticsearch" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithExceptionDetails", "WithCorrelationId" ],
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {CorrelationId} {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "Logs/log-.txt",
"rollingInterval": "Day",
"retainedFileCountLimit": 14,
"shared": true
}
},
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://localhost:9200",
"indexFormat": "myapp-logs-{0:yyyy.MM}",
"autoRegisterTemplate": true,
"autoRegisterTemplateVersion": "ESv7"
}
}
]
},
"ElasticApm": {
"ServerUrls": "http://localhost:8200",
"ServiceName": "MyApp.Service",
"Environment": "Development",
"SecretToken": "",
"TransactionSampleRate": 1.0
}
}
π¦ Provided Extension Methods
| Method | Description |
|---|---|
AddLogging(IConfiguration) |
Creates and configures a Serilog Logger with enrichment and filters. |
AddApm() |
Adds Elastic APM to the application services. |
UseLogging(IConfiguration, ILoggerFactory) |
Connects Serilog to ASP.NET Coreβs logging pipeline. |
π§ͺ Tests
Run the following command to run the tests:
dotnet test .\Tests\Netrilo.Infrastructure.Common.Logging.UnitTests\Netrilo.Infrastructure.Common.Logging.UnitTests.csproj
π License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Elastic.Apm.NetCoreAll (>= 1.34.0)
- Serilog (>= 4.3.0)
- Serilog.AspNetCore (>= 9.0.0)
- Serilog.Enrichers.CorrelationId (>= 3.0.1)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Logging (>= 9.0.2)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.