Akka.Logger.log4net 1.5.69

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

Akka.Logger.log4net

  • This plugin integrates log4net with Akka.NET, and enhances your Akka.NET logging capabilities by integrating with log4net. For detailed usage and configuration examples, see the sections below or explore our documentation.

  • Currently targetting Log4Net 2.0.17

Using the log4net Logger Integration

With log4net, you can enrich your logs with both custom and automatic context information, such as file names, line numbers, and method names. This makes your logs more informative and easier to trace.

Obtaining an ILoggerAdapter with Contextual Logging

Use Log4NetLoggingAdapterExtensions to get an ILoggerAdapter that supports enriched logging:

Examples
Logging with Automatic Context Information

Simply calling ForContext without arguments adds useful context like file name, line number, and method name to your logs:

var logger = Context.GetLogger().ForContext();

logger.Info("This log includes automatic context information.");
Logging with Custom Properties

Add custom properties to your logs as follows:

var logger = Context.GetLogger()
    .ForContext("CustomProperty1", "CustomValue1")
    .ForContext("CustomProperty2", "CustomValue2");

logger.Info("This log has custom properties.");

Or, use a dictionary for multiple properties (an enumerable of key-value pairs):

var properties = new Dictionary<string, object?>
{
    ["UserId"] = "user123",
    ["Operation"] = "UpdateProfile"
};

var logger = Context.GetLogger().ForContext(properties);
logger.Info("User profile updated.");

This will log a message with custom properties UserId and Operation, along with the source file name, line number, and method name.

Configuring log4net for Custom Properties

To include custom properties in your logs, configure log4net like this:

<log4net>
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
	<layout type="log4net.Layout.PatternLayout">
	  <conversionPattern value="%date [%thread] [%file(%line)] [%property{LogSource} - %property{ActorPath}] %-5level %logger - UserId=%property{UserId}, Operation=%property{Operation} %class.%method - %message%newline" />
	</layout>
  </appender>
  <root>
	<level value="INFO" />
	<appender-ref ref="ConsoleAppender" />
  </root>
</log4net>

This setup ensures your logs include all the specified details, making them more informative and easier to navigate.

Configuration via Akka.Hosting

Log4net can be registered as the Akka.NET logger through the Akka.Hosting integration. This approach provides a clean, modern way to wire up logging in hosted applications using dependency injection.

Use the ConfigureLoggers method on your Akka configuration builder:

using Akka.Hosting;
using Akka.Logger.log4net;

// builder is a HostApplicationBuilder / WebApplicationBuilder
builder.Services.AddAkka("MySystem", configurationBuilder =>
{
    configurationBuilder.ConfigureLoggers(loggerConfigBuilder =>
    {
        loggerConfigBuilder.ClearLoggers();              // remove Akka's default console logger
        loggerConfigBuilder.AddLogger<Log4NetLogger>();  // route Akka events into log4net
    });
});

Log4net appenders and the repository are configured as usual via log4net.config (using XmlConfigurator) or programmatically via the log4net API.

For a complete runnable example, see src/Examples/Akka.Logger.log4net.HostingDemo.

Conclusion

The log4net integration enhances Akka.NET's logging by allowing for detailed contextual information in logs. This not only improves diagnostics but also aids in understanding the execution flow and context of log messages.

Maintainer

  • Akka.NET Team
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 is compatible.  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.
  • .NETFramework 4.7.2

  • .NETStandard 2.0

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.5.69 3,936 6/16/2026
1.5.60 2,365 2/10/2026
1.5.25 18,434 6/19/2024
1.3.1 176,652 10/9/2017
1.3.0 13,910 9/1/2017
1.2.9 10,871 4/25/2017
1.1.1 8,589 7/25/2016
1.0.8 2,110 4/28/2016
1.0.6 2,703 1/18/2016

Support for Akka 1.3.1 and .NET Core