Skip to content

Fix semantic logging bug #701#702

Merged
Aaronontheweb merged 7 commits into
akkadotnet:devfrom
Arkatufus:#701-Fix-semantic-logging
Jan 20, 2026
Merged

Fix semantic logging bug #701#702
Aaronontheweb merged 7 commits into
akkadotnet:devfrom
Arkatufus:#701-Fix-semantic-logging

Conversation

@Arkatufus
Copy link
Copy Markdown
Contributor

@Arkatufus Arkatufus commented Jan 20, 2026

Fixes #701

Changes

  • Refactor all LoggerConfigBuilder properties to be optional
  • Refactor message formatting code

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Copy Markdown
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review

Comment on lines +81 to +88
state["ActorPath"] = path.ToString();
state["Timestamp"] = log.Timestamp;
state["Thread"] = log.Thread.ManagedThreadId;
state["LogSource"] = log.LogSource;

// Add Akka metadata properties
state["ActorPath"] = path.ToString();
state["Timestamp"] = log.Timestamp;
state["Thread"] = log.Thread.ManagedThreadId;
state["LogSource"] = log.LogSource;

// Add {OriginalFormat} key per MEL convention for structured logging
// This allows MEL sinks to recognize and preserve the message template
state["{OriginalFormat}"] = log.GetTemplate();
// Add {OriginalFormat} key per MEL convention for structured logging
// This allows MEL sinks to recognize and preserve the message template
state["{OriginalFormat}"] = log.GetTemplate();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata will now always be included with the log

Comment on lines +95 to +106
try
{
return log.ToString();
}
catch
{
if(log.Message is LogMessage msg)
return $"Received a malformed formatted message. Log level: [{log.LogLevel()}], Template: [{msg.Format}], args: [{string.Join(",", msg.Unformatted())}]";

return $"Received a malformed formatted message. Log level: [{log.LogLevel()}], Message: [{log.Message}]";
}
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix, use the log message internal formatter

Comment on lines +121 to +133
var sb = new StringBuilder();

if(LogLevel is not null)
sb .Append("akka.loglevel=").AppendLine(ParseLogLevel(LogLevel).ToHocon());

if(_loggers.Count > 0)
sb.Append("akka.loggers=[").Append(string.Join(",", _loggers.Select(t => $"\"{t.AssemblyQualifiedName}\""))).AppendLine("]");

if(LogConfigOnStart is not null)
sb.Append("akka.log-config-on-start=").AppendLine(LogConfigOnStart.Value.ToHocon());

if(_logMessageFormatter is not null)
sb.Append("akka.logger-formatter=").AppendLine(_logMessageFormatter.AssemblyQualifiedName.ToHocon());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make all option properties optional, options should not force specific HOCON values.

Copy link
Copy Markdown
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

var loggers = config.GetStringList("akka.loggers");
loggers.Count.Should().Be(1);
loggers[0].Should().Contain("Akka.Event.DefaultLogger");
config.GetString("akka.logger-formatter").Should().Contain("SemanticLogMessageFormatter");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit 09abbef into akkadotnet:dev Jan 20, 2026
2 checks passed
This was referenced May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic logging isn't working in Akka.Hosting

2 participants