Skip to content

Fix WithDefaultLogMessageFormatter rejecting built-in formatters#711

Merged
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/703-log-message-formatter-validation
Feb 10, 2026
Merged

Fix WithDefaultLogMessageFormatter rejecting built-in formatters#711
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/703-log-message-formatter-validation

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Member

Closes #703

Summary

  • Fix: WithDefaultLogMessageFormatter<T>() now accepts SemanticLogMessageFormatter and DefaultLogMessageFormatter, which have private constructors (they use singleton Instance properties). The validation was too strict — GetConstructor([]) only finds public constructors, but core Akka.NET's Settings.cs already special-cases these types at runtime.
  • Deprecate: Mark WithDefaultLogMessageFormatter<T>() as [Obsolete] since SemanticLogMessageFormatter is now the default as of Akka.NET 1.5.58. The method still works for custom ILogMessageFormatter implementations.

Test plan

  • New test: SemanticLogMessageFormatterShouldBeAcceptedTest — verifies the formatter is accepted and produces the correct Settings.LogFormatter
  • New test: DefaultLogMessageFormatterShouldBeAcceptedTest — same for DefaultLogMessageFormatter
  • Existing test: InvalidLogMessageFormatterThrowsTest — still rejects formatters without a public parameterless constructor
  • Existing test: TransformMessagesTest — custom formatters still work
  • API approval snapshot updated with new [Obsolete] attribute

…adotnet#703)

SemanticLogMessageFormatter and DefaultLogMessageFormatter have private
constructors (they use singleton Instance properties). The validation in
LoggerConfigBuilder.LogMessageFormatter incorrectly rejected them because
GetConstructor([]) only finds public constructors. Core Akka.NET's
Settings.cs already special-cases these types at runtime.

Skip the constructor check for built-in formatter types. Also deprecate
WithDefaultLogMessageFormatter<T>() since SemanticLogMessageFormatter is
now the default as of Akka.NET 1.5.58.
@Aaronontheweb Aaronontheweb merged commit bbb95ec into akkadotnet:dev Feb 10, 2026
2 checks passed
@Aaronontheweb Aaronontheweb deleted the fix/703-log-message-formatter-validation branch February 10, 2026 18:33
Aaronontheweb added a commit to Aaronontheweb/Akka.Hosting that referenced this pull request Feb 10, 2026
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.

Unable to set SemanticLogMessageFormatter as default because it doesn't have parameterless ctor

1 participant