Netrilo.Infrastructure.Common.Logging 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Netrilo.Infrastructure.Common.Logging --version 1.0.3
                    
NuGet\Install-Package Netrilo.Infrastructure.Common.Logging -Version 1.0.3
                    
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="Netrilo.Infrastructure.Common.Logging" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Netrilo.Infrastructure.Common.Logging" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Netrilo.Infrastructure.Common.Logging" />
                    
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 Netrilo.Infrastructure.Common.Logging --version 1.0.3
                    
#r "nuget: Netrilo.Infrastructure.Common.Logging, 1.0.3"
                    
#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 Netrilo.Infrastructure.Common.Logging@1.0.3
                    
#: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=Netrilo.Infrastructure.Common.Logging&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Netrilo.Infrastructure.Common.Logging&version=1.0.3
                    
Install as a Cake Tool

Netrilo.Infrastructure.Common.Logging

Part of the Netrilo.Infrastructure SDK

πŸ“¦ NuGet

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 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. 
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
1.0.4 314 9/15/2025
1.0.3 283 9/15/2025
1.0.2 122 9/12/2025
1.0.1 129 9/12/2025