Summary
The log4net plugin does not call TryGetProperties() from LogEventExtensions, which means context properties set via the core WithContext() API (added in Akka.NET 1.5.60) are silently dropped.
Current Behavior
Log4net has its own custom context enrichment system (ForContext() / Log4NetPayload / SetContextProperties()), but it only extracts properties from Log4NetPayload. It never calls TryGetProperties(), so properties added via the core WithContext() extension are ignored.
In Log4NetLogger.cs:
var (message, properties) = logEvent.Message is Log4NetPayload log4NetPayload
? (log4NetPayload.Message, log4NetPayload.Properties)
: (logEvent.Message, Log4NetPayload.Empty.Properties);
Expected Behavior
The logger should call logEvent.TryGetProperties(out var properties) to merge both WithContext() properties and message template properties, the same way the NLog and Serilog plugins do.
Reference Implementations
NLog (NLogLogger.cs):
if (logEvent.TryGetProperties(out var properties))
{
foreach (var prop in properties)
{
logEventInfo.Properties[prop.Key] = prop.Value;
}
}
Serilog (SerilogLogger.cs) - recently fixed in the same release cycle.
Suggested Fix
In Log4NetLogger.CreateLoggingEvent(), add a TryGetProperties() call and merge the resulting properties into the LoggingEventData.Properties. The custom ForContext() API can be deprecated in favor of core WithContext(), matching what was done for Serilog.
Tests should be added following the pattern in the NLog plugin's WithContextSpecs.cs.
Summary
The log4net plugin does not call
TryGetProperties()fromLogEventExtensions, which means context properties set via the coreWithContext()API (added in Akka.NET 1.5.60) are silently dropped.Current Behavior
Log4net has its own custom context enrichment system (
ForContext()/Log4NetPayload/SetContextProperties()), but it only extracts properties fromLog4NetPayload. It never callsTryGetProperties(), so properties added via the coreWithContext()extension are ignored.In
Log4NetLogger.cs:Expected Behavior
The logger should call
logEvent.TryGetProperties(out var properties)to merge bothWithContext()properties and message template properties, the same way the NLog and Serilog plugins do.Reference Implementations
NLog (
NLogLogger.cs):Serilog (
SerilogLogger.cs) - recently fixed in the same release cycle.Suggested Fix
In
Log4NetLogger.CreateLoggingEvent(), add aTryGetProperties()call and merge the resulting properties into theLoggingEventData.Properties. The customForContext()API can be deprecated in favor of coreWithContext(), matching what was done for Serilog.Tests should be added following the pattern in the NLog plugin's
WithContextSpecs.cs.