Akka.Logger.Serilog 1.5.60

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

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

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, CorrelationId from WithContext())
  • 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, the ForContext() extension method, and Context.GetLogger<SerilogLoggingAdapter>() are deprecated as of Akka.Logger.Serilog 1.5.60. Use the standard ILoggingAdapter with WithContext() 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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Akka.Logger.Serilog:

Package Downloads
SharpPulsar

SharpPulsar is Apache Pulsar Client built using Akka.net

SnD.Sdk

SDK for Sneaks&Data OSS Projects

EventSaucing

An event source stack based on NEventStore and Akka

Cy.Bee.Core

Cy.Bee.Core assembles well-known packages for rapid application prototyping in contexts of Cyber Physical System (CPS). The Cy.Bee.Core rely on ReactiveX, EFCore and Akka.NET to create the basic functionalities for Cy.Bee.

Cy.Bee.Testkit

Cy.Bee.Core assembles well-known packages for rapid application prototyping in contexts of Cyber Physical System (CPS). The Cy.Bee.Testkit re-models the behavior of xUnit to archieve sequencial test scenarios to maximize human-accessiblity.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.60 21,920 2/10/2026
1.5.59 12,575 1/27/2026
1.5.58 16,272 1/9/2026
1.5.25 787,316 6/17/2024
1.5.12.1 388,784 9/14/2023
1.5.12 14,092 8/31/2023
1.5.7 255,327 5/19/2023
1.5.0.1 65,897 3/15/2023
1.5.0 36,118 3/2/2023
1.5.0-beta5 449 3/1/2023
1.4.42 246,403 9/23/2022
1.4.26 440,722 10/7/2021
1.4.25 17,177 9/9/2021
1.4.17 162,361 3/17/2021
1.4.11 247,497 11/7/2020
1.4.10 12,334 10/28/2020
1.4.8 110,048 7/1/2020
1.4.3 63,336 3/27/2020
1.4.1 6,001 3/11/2020
1.4.1-rc3 645 3/10/2020
Loading failed

* [Update Akka.NET to 1.5.60](https://github.com/akkadotnet/akka.net/releases/tag/1.5.60)
* [Add WithContext() support and deprecate Serilog-specific ForContext()](https://github.com/akkadotnet/Akka.Logger.Serilog/pull/310)
* [Convert tests from deprecated APIs to WithContext() and fix flaky net471 tests](https://github.com/akkadotnet/Akka.Logger.Serilog/pull/312)

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:**
- `SerilogLoggingAdapter` class is now marked `[Obsolete]` - use the standard `ILoggingAdapter` with `WithContext()` instead
- `ForContext()` extension method is now marked `[Obsolete]` - use `WithContext()` 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 custom `ILogEventEnricher` implementations
- **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-specific `ForContext()` extension method on `ILoggingAdapter` is deprecated
- **`PropertyEnricher` parameters** — passing `PropertyEnricher` objects as log message parameters still works
- **Level switches and minimum level overrides** — no changes to log level filtering behavior

**Migration:**
```csharp
// 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).