applogger-2do
2.5.0
dotnet add package applogger-2do --version 2.5.0
NuGet\Install-Package applogger-2do -Version 2.5.0
<PackageReference Include="applogger-2do" Version="2.5.0" />
<PackageVersion Include="applogger-2do" Version="2.5.0" />
<PackageReference Include="applogger-2do" />
paket add applogger-2do --version 2.5.0
#r "nuget: applogger-2do, 2.5.0"
#:package applogger-2do@2.5.0
#addin nuget:?package=applogger-2do&version=2.5.0
#tool nuget:?package=applogger-2do&version=2.5.0
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 |
Recommended columns in Discover
@timestamp— whenlog.level— levelCustomer— which customerApplication— which API/pluginmessage— the log messageRequestPath— endpointCorrelationId— to trace a requestMachineName— 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 | 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
- Elastic.Serilog.Sinks (>= 8.12.3)
- Serilog (>= 4.3.1)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Extensions.Logging (>= 8.0.0)
- Serilog.Sinks.Console (>= 6.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.