applogger-2do 2.5.0

dotnet add package applogger-2do --version 2.5.0
                    
NuGet\Install-Package applogger-2do -Version 2.5.0
                    
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="applogger-2do" Version="2.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="applogger-2do" Version="2.5.0" />
                    
Directory.Packages.props
<PackageReference Include="applogger-2do" />
                    
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 applogger-2do --version 2.5.0
                    
#r "nuget: applogger-2do, 2.5.0"
                    
#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 applogger-2do@2.5.0
                    
#: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=applogger-2do&version=2.5.0
                    
Install as a Cake Addin
#tool nuget:?package=applogger-2do&version=2.5.0
                    
Install as a Cake Tool

AppLogger

Structured logging to Elasticsearch via Serilog. NuGet package: applogger-2do

What it does

  • Automatically logs all HTTP requests (method, path, status code, response time)
  • Catches unhandled exceptions with full stack trace
  • Adds a correlation ID to every request (for tracing the entire flow)
  • Enriches all logs with Customer, AppName, Environment and MachineName

Requirements

  • .NET 8+ (ASP.NET Core)
  • Does not work with .NET Framework

Setup for ASP.NET Core APIs

1. Add the NuGet package

dotnet add package applogger-2do

2. Add the Elasticsearch section to appsettings.json

{
  "Elasticsearch": {
    "Endpoint": "https://your-cluster.es.westeurope.azure.elastic-cloud.com:9243",
    "ApiKeyBase64": "your-base64-api-key",
    "Customer": "",
    "AppName": "",
    "Environment": "prod"
  }
}
Field Required Description
Endpoint Yes Elasticsearch cluster URL
ApiKeyBase64 Yes Base64-encoded API key (id:secret)
Customer No Customer name — used for filtering in Kibana
AppName No* API name. *Falls back to assembly name if empty
PluginName No Plugin name (takes priority over AppName)
Environment No Default: "prod"

3. Update Program.cs (2 lines)

using AppLogger;

var builder = WebApplication.CreateBuilder(args);

builder.UseAppLogger();  // <-- configures Serilog from appsettings.json

// ... rest of your DI setup ...

var app = builder.Build();

app.UseAppLoggerMiddleware();  // <-- request logging, exception handling, correlation IDs

// ... rest of your pipeline ...
app.Run();

That's it. All requests, exceptions and your own log calls are now sent to Elasticsearch.

What is logged automatically

Each HTTP request produces a log entry like:

HTTP GET /api/orders responded 200 in 42ms
HTTP POST /api/items responded 201 in 128ms
HTTP GET /api/missing failed with exception after 3ms. CorrelationId: a3f2-b1c4-...

Logging in code

Use Serilog's static Log class. All fields (Customer, AppName, Environment etc.) are added automatically.

using Serilog;

// Information
Log.Information("Order {OrderId} created for {Customer}", orderId, customerName);

// Warning
Log.Warning("Stock for item {Item} below minimum: {Qty} pcs", itemNo, qty);

// Error with exception
try
{
    await ProcessOrder(order);
}
catch (Exception ex)
{
    Log.Error(ex, "Failed to process order {OrderId}", order.Id);
    throw;  // let middleware handle the HTTP response
}

Structured logging

Always use {Placeholder}not string interpolation:

// CORRECT — fields become searchable in Kibana:
Log.Information("Order {OrderId} created", orderId);

// WRONG — the value gets embedded in the text:
Log.Information($"Order {orderId} created");

Fields on each log entry

Field Description Example
Customer Customer name (from config) acme-corp
Application API or plugin name order-api
PluginName Only for plugins BudgetPlugin
Environment Environment prod / development
MachineName Server name WEB-SERVER-01
CorrelationId Unique ID per request a3f2-b1c4-...
RequestPath HTTP endpoint /api/orders
RequestMethod HTTP method GET / POST
StatusCode HTTP status code 200 / 500
ElapsedMs Response time in milliseconds 42
message Your log message Order 123 created
log.level Log level Information / Error
@timestamp Timestamp (UTC) 2026-05-13T10:30:00Z

Correlation ID

The middleware adds a correlation ID to every request. All Log.*() calls within the same request automatically share the same correlation ID — regardless of layer (Controller, Service, Repository).

Search CorrelationId : "a3f2-..." in Kibana to see the full flow for a single request.

Kibana

Data Streams

Logs are organized in data streams:

logs-2do-{customer}-{appname}-{environment}

Create a data view in Kibana with pattern logs-2do-* to see all logs.

Useful KQL queries

Query What it finds
Customer : "acme-corp" All logs for a customer
Application : "order-api" Logs from a specific API
log.level : "Error" Errors only
log.level : "Error" AND Customer : "acme-corp" Errors for a specific customer
CorrelationId : "a3f2-b1c4-..." All logs from a single request
PluginName : "BudgetPlugin" Logs from a specific plugin
Environment : "prod" Production logs only
  • @timestamp — when
  • log.level — level
  • Customer — which customer
  • Application — which API/plugin
  • message — the log message
  • RequestPath — endpoint
  • CorrelationId — to trace a request
  • MachineName — which server

NuGet Dependencies

  • Serilog 4.x
  • Serilog.Extensions.Logging 8.x
  • Serilog.Sinks.Console 6.x
  • Serilog.Enrichers.Environment 3.x
  • Elastic.Serilog.Sinks 8.x

Changelog

Version Change
2.4.0 Automatic HTTP request logging (method, path, status code, response time) built into middleware. Removed Serilog.AspNetCore dependency.
2.3.0 Removed Serilog.AspNetCore to fix .NET 9 assembly conflict on publish. Changed UseAppLogger() from IHostBuilder to WebApplicationBuilder.
2.2.0 Added FrameworkReference to Microsoft.AspNetCore.App.
2.0.0 Initial version with ASP.NET Core support via UseAppLogger().
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
2.5.0 98 5/19/2026
2.4.1 91 5/13/2026
2.4.0 100 5/13/2026
2.3.0 96 5/13/2026
2.2.0 114 3/27/2026
2.1.0 99 3/26/2026
2.0.0 101 3/25/2026
1.0.0 100 3/24/2026