Akka.Logger.Serilog 1.5.60
Akka.Logger.Serilog
This is the Serilog integration plugin for Akka.NET. It routes Akka.NET's internal log events through the Serilog pipeline, giving you structured logging with full access to Serilog's enrichment, filtering, and sink ecosystem.
Targets Serilog 2.12.0.
How It Works
When you configure Akka.NET to use the Serilog logger, all log events from Akka.NET (actor lifecycle messages, dead letters, your own ILoggingAdapter calls, etc.) flow through a SerilogLogger actor that writes them to Serilog's global Log.Logger.
This means your entire Serilog configuration — enrichers, sinks, filters, output templates, minimum levels — applies to Akka.NET log events just like any other log event in your application. Akka.Logger.Serilog doesn't replace or interfere with your Serilog pipeline; it plugs into it.
The following Akka-specific properties are automatically added to every log event:
| Property | Description |
|---|---|
SourceContext |
The full type name of the logging class |
ActorPath |
The path of the actor that produced the log message |
LogSource |
The Akka.NET log source string |
Thread |
The managed thread ID (zero-padded) |
Timestamp |
When the log event was created |
These properties are available in output templates (e.g., {ActorPath}) and in structured log sinks (e.g., Seq, Elasticsearch).
Setup
Option 1: Akka.Hosting (Recommended)
using Akka.Hosting;
using Akka.Logger.Serilog;
var builder = WebApplication.CreateBuilder(args);
// Configure Serilog as usual
builder.Host.UseSerilog((context, config) =>
{
config
.ReadFrom.Configuration(context.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console();
});
// Register Akka.NET with Serilog logging
builder.Services.AddAkka("MySystem", configurationBuilder =>
{
configurationBuilder.WithLogging(loggerConfigBuilder =>
{
loggerConfigBuilder.AddSerilogLogging();
});
});
AddSerilogLogging() automatically configures both SerilogLogger and SerilogLogMessageFormatter, enabling semantic logging out of the box.
Option 2: HOCON Configuration
akka {
loggers = ["Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog"]
loglevel = DEBUG
# Required for semantic/structured logging (named template properties)
logger-formatter = "Akka.Logger.Serilog.SerilogLogMessageFormatter, Akka.Logger.Serilog"
}
Make sure you configure the global Serilog.Log.Logger before creating your ActorSystem:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate:
"{Timestamp:HH:mm:ss} [{Level:u3}] {ActorPath} - {Message:lj}{NewLine}{Exception}")
.CreateLogger();
var system = ActorSystem.Create("MySystem", hoconConfig);
Semantic (Structured) Logging
When SerilogLogMessageFormatter is configured (automatic with AddSerilogLogging(), manual with HOCON), named template properties in your log messages are preserved as structured Serilog properties:
var log = Context.GetLogger();
// Named properties - UserId and Action become structured Serilog properties
log.Info("User {UserId} performed {Action}", userId, "login");
// Serilog destructuring operator - User is destructured into its component properties
log.Info("Processing {@User}", userObject);
// Format specifiers work too
log.Info("Total: {Amount:C2}", 1234.56);
These properties appear in your Serilog sinks exactly as they would if you logged directly with Serilog's ILogger.
Adding Context Properties To Your Logs
As of Akka.NET 1.5.60, you can use the built-in WithContext() method on any ILoggingAdapter to add persistent properties to all log messages produced by that adapter. These properties automatically flow through to Serilog as structured properties.
public class OrderProcessorActor : ReceiveActor
{
private readonly ILoggingAdapter _log;
public OrderProcessorActor(string tenantId, string region)
{
// Context properties persist for all messages logged with this adapter
_log = Context.GetLogger()
.WithContext("TenantId", tenantId)
.WithContext("Region", region);
Receive<ProcessOrder>(order =>
{
// This log event will include TenantId, Region, AND OrderId
_log.Info("Processing order {OrderId} for {Amount:C2}", order.Id, order.Amount);
});
}
}
WithContext() is part of core Akka.NET and works with all logging backends (Serilog, NLog, Microsoft.Extensions.Logging), not just Serilog.
Your Serilog Configuration
Your existing Serilog configuration works exactly as before. Akka.Logger.Serilog writes into the Serilog pipeline — it doesn't replace or modify it.
Global Enrichers
All of your global enrichers apply to Akka.NET log events:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // ambient async-local context
.Enrich.WithMachineName() // machine name on every event
.Enrich.WithProcessId() // PID on every event
.Enrich.WithThreadId() // thread ID on every event
.Enrich.WithProperty("Application", "OrderService") // static property
.WriteTo.Console()
.CreateLogger();
These enrichers fire on every log event that passes through the Serilog pipeline, including all events from Akka.NET.
JSON / appsettings.json Configuration
JSON-based Serilog configuration is fully supported. All enrichers, sinks, properties, and level overrides configured in your appsettings.json work with Akka.NET log events:
{
"Serilog": {
"Using": ["Serilog.Sinks.Console", "Serilog.Enrichers.Environment"],
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Error",
"Microsoft": "Error"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3} {ActorPath} - {Message:lj} {Exception}{NewLine}"
}
}
],
"Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId"],
"Properties": {
"Application": "MyService"
}
}
}
Note that {ActorPath} and other Akka metadata properties can be used directly in output templates.
Serilog's LogContext vs. Akka's WithContext
Serilog's LogContext.PushProperty() uses async-local (thread-local on .NET Framework) ambient context. Because Akka.NET processes messages on its own dispatcher threads, LogContext properties pushed by the caller won't automatically flow into an actor's log messages — this is inherent to the Akka threading model.
For enriching log messages inside actors, use WithContext() — it travels with the Akka LogEvent across thread boundaries:
// This works - WithContext travels through the Akka pipeline
var log = Context.GetLogger().WithContext("CorrelationId", correlationId);
log.Info("Processing request"); // CorrelationId is present
// This does NOT work inside actors - LogContext is thread-local
using (LogContext.PushProperty("CorrelationId", correlationId))
{
actorRef.Tell(message); // actor processes on a different thread
}
LogContext.PushProperty() is still useful for non-actor code (ASP.NET middleware, background services, etc.) where you control the async context.
Log Filtering
Akka.Logger.Serilog supports Akka.NET's built-in log filtering to reduce log noise before messages reach Serilog. This is especially useful on high-volume systems.
When to Use Akka LogFilter vs Serilog Native Filtering
Use Akka's LogFilter when:
- Filtering on
LogSource(actor paths, class names) — this Akka-specific metadata isn't available in Serilog's filter pipeline - You want to filter messages before they enter the Serilog pipeline (better performance on high-volume systems)
- Using source-only filters (no string allocations required)
var filters = new LogFilterBuilder()
.ExcludeSourceStartingWith("Akka.Remote.EndpointWriter")
.ExcludeSourceContaining("Heartbeat")
.Build();
var bootstrap = BootstrapSetup.Create()
.WithSetup(filters);
Use Serilog's native filtering when:
- Filtering on Serilog enricher properties (e.g.,
TenantId,CorrelationIdfromWithContext()) - Using complex predicate logic
- Filtering on properties added via
LogContext.PushProperty()
Log.Logger = new LoggerConfiguration()
.Filter.ByExcluding(evt =>
evt.Properties.TryGetValue("TenantId", out var val) &&
val.ToString() == "\"internal\"")
.WriteTo.Console()
.CreateLogger();
Important limitation: Context properties added via WithContext() or LogContext.PushProperty() are applied after Akka's LogFilter runs, so they cannot be filtered using Akka's LogFilter. Use Serilog's native .Filter.ByExcluding() for enricher-based filtering.
Deprecated: SerilogLoggingAdapter and ForContext()
Note:
SerilogLoggingAdapter, theForContext()extension method, andContext.GetLogger<SerilogLoggingAdapter>()are deprecated as of Akka.Logger.Serilog 1.5.60. Use the standardILoggingAdapterwithWithContext()instead.
These deprecated APIs still work and will continue to work — they produce compiler warnings but will not be removed until a future major version. Your existing code will compile and run correctly.
If you are migrating from ForContext():
// Old (deprecated - still works, produces compiler warning)
var log = Context.GetLogger<SerilogLoggingAdapter>()
.ForContext("TenantId", "TENANT-001");
// New (recommended)
var log = Context.GetLogger()
.WithContext("TenantId", "TENANT-001");
Why the change? WithContext() is built into core Akka.NET and works identically across all logging backends. This means you can write logging code once and switch between Serilog, NLog, or Microsoft.Extensions.Logging without changing your actor code.
Building this solution
To run the build script associated with this solution, execute the following:
Windows
c:\> build.cmd all
Linux / OS X
c:\> build.sh all
If you need any information on the supported commands, please execute the build.[cmd|sh] help command.
This build script is powered by FAKE; please see their API documentation should you need to make any changes to the build.fsx file.
No packages depend on Akka.Logger.Serilog.
- Update Akka.NET to 1.5.60
- Add WithContext() support and deprecate Serilog-specific ForContext()
- Convert tests from deprecated APIs to WithContext() and fix flaky net471 tests
This release adds support for Akka.NET 1.5.60's built-in WithContext() logging context enrichment API. Context properties set via WithContext() on any ILoggingAdapter now automatically flow through to Serilog as structured properties.
Deprecations:
SerilogLoggingAdapterclass is now marked[Obsolete]- use the standardILoggingAdapterwithWithContext()insteadForContext()extension method is now marked[Obsolete]- useWithContext()instead
These deprecated APIs still work and will continue to work — they just produce compiler warnings. They will not be removed until a future major version.
What's NOT Changing:
Your existing Serilog configuration is completely unaffected. This deprecation only affects how you create logging adapters inside Akka.NET actor code — it does not change anything about the Serilog pipeline itself.
Specifically, all of the following continue to work exactly as before:
- Your Serilog
LoggerConfiguration— whether configured via C# code,appsettings.json, or any other Serilog configuration provider - Global enrichers —
FromLogContext(),WithMachineName(),WithProcessId(),WithThreadId(), and any customILogEventEnricherimplementations - Global properties — static properties added via
Enrich.WithProperty()or the"Properties"section in JSON config - Output templates —
{ActorPath},{LogSource},{Thread}, and all other Akka metadata properties are still emitted exactly as before - Sinks — Console, Seq, Elasticsearch, file sinks, and all other Serilog sinks are unaffected
LogContext.PushProperty()— Serilog's ambient context API works the same as always- Serilog's native
ILogger.ForContext()— this is Serilog's own API and is NOT deprecated; only the Akka-specificForContext()extension method onILoggingAdapteris deprecated PropertyEnricherparameters — passingPropertyEnricherobjects as log message parameters still works- Level switches and minimum level overrides — no changes to log level filtering behavior
Migration:
// Old (deprecated - produces compiler warning, but still works)
var log = Context.GetLogger<SerilogLoggingAdapter>()
.ForContext("TenantId", "TENANT-001");
// New (recommended)
var log = Context.GetLogger()
.WithContext("TenantId", "TENANT-001");
The new WithContext() API is part of core Akka.NET and works identically across all logging backends (Serilog, NLog, Microsoft.Extensions.Logging).
.NET 6.0
- Akka (>= 1.5.60)
- Akka.Hosting (>= 1.5.59)
- Serilog (>= 2.12.0)
.NET Standard 2.0
- Akka (>= 1.5.60)
- Akka.Hosting (>= 1.5.59)
- Serilog (>= 2.12.0)
| Version | Downloads | Last updated |
|---|---|---|
| 1.5.63 | 1 | 03/26/2026 |
| 1.5.60 | 1 | 02/20/2026 |
| 1.5.59 | 1 | 02/02/2026 |
| 1.5.58 | 2 | 02/02/2026 |
| 1.5.25 | 1 | 02/20/2026 |
| 1.5.12.1 | 2 | 02/02/2026 |
| 1.5.12 | 2 | 02/02/2026 |
| 1.5.7 | 2 | 02/02/2026 |
| 1.5.0.1 | 1 | 03/22/2026 |
| 1.5.0 | 2 | 02/02/2026 |
| 1.5.0-beta5 | 1 | 03/21/2026 |
| 1.4.42 | 2 | 02/02/2026 |
| 1.4.26 | 1 | 03/21/2026 |
| 1.4.25 | 2 | 02/02/2026 |
| 1.4.17 | 1 | 03/21/2026 |
| 1.4.11 | 0 | 11/07/2020 |
| 1.4.10 | 2 | 02/02/2026 |
| 1.4.8 | 2 | 02/02/2026 |
| 1.4.3 | 2 | 02/02/2026 |
| 1.4.1 | 2 | 02/02/2026 |
| 1.4.1-rc3 | 1 | 02/20/2026 |
| 1.4.1-RC1 | 2 | 02/02/2026 |
| 1.3.11 | 1 | 02/20/2026 |
| 1.3.10 | 1 | 02/02/2026 |
| 1.3.9 | 1 | 03/21/2026 |
| 1.3.6 | 2 | 02/02/2026 |
| 1.3.3 | 1 | 02/02/2026 |
| 1.3.0 | 2 | 02/02/2026 |
| 1.2.0 | 2 | 02/02/2026 |
| 1.1.3 | 2 | 02/02/2026 |
| 1.1.2 | 2 | 02/02/2026 |
| 1.1.1 | 2 | 02/02/2026 |
| 1.0.8 | 2 | 02/02/2026 |
| 1.0.7 | 2 | 02/02/2026 |
| 1.0.6 | 2 | 02/02/2026 |
| 1.0.5 | 0 | 12/03/2015 |
| 1.0.4 | 2 | 02/02/2026 |
| 1.0.3 | 2 | 02/02/2026 |
| 1.0.2 | 2 | 02/02/2026 |
| 1.0.1 | 2 | 02/02/2026 |
| 1.0.0 | 2 | 02/02/2026 |
| 1.0.0-dev1504032244 | 1 | 03/21/2026 |
| 0.8.0 | 2 | 02/02/2026 |
| 0.7.1 | 1 | 03/21/2026 |
| 0.7.0 | 2 | 02/02/2026 |