Skip to content

Conversation

@Aaronontheweb
Copy link
Member

Summary

Adds semantic logging support to leverage Akka.NET's new semantic logging APIs introduced in version 1.5.56.

This major enhancement enables Microsoft.Extensions.Logging (MEL) to receive properly structured state dictionaries instead of pre-formatted strings, unlocking the full power of structured logging for all MEL sinks (Serilog, Seq, Application Insights, etc.).

Changes

  • LoggerFactoryLogger.cs: Completely rewrote Log() method to extract structured properties and create MEL state dictionary
  • SemanticLoggingSpecs.cs: Added comprehensive test suite with 7 tests covering all semantic logging scenarios

Test Coverage

New test suite includes:

  • Named and positional template properties
  • Multiple properties handling
  • Akka metadata preservation (ActorPath, Timestamp, Thread, LogSource)
  • OriginalFormat key verification (MEL convention)
  • Format specifiers handling
  • Empty properties handling

All existing tests pass (457/458, 1 skipped - same as before).

Impact

This change enables MEL sinks to:

  • Query log entries by structured property values
  • Correlate events across distributed systems
  • Create rich dashboard visualizations
  • Perform advanced filtering and analysis

Example State Dictionary

Before: MEL received formatted string "User 12345 with email [email protected] logged in"

After: MEL receives structured state:

{
  "UserId": 12345,
  "Email": "[email protected]",
  "ActorPath": "akka://sys/user/myactor",
  "Timestamp": <DateTime>,
  "Thread": 17,
  "LogSource": "MyActor",
  "OriginalFormat": "User UserId with email Email logged in"
}

Backwards Compatibility

Fully backwards compatible through conditional TryGetProperties() check. Falls back to ToString() for non-structured messages.

Dependencies

Requires Akka.NET >= 1.5.56 (not yet released)

Notes

  • CI/CD will fail until Akka.NET 1.5.56 is published to NuGet
  • This PR is ready for review but should not be merged until the Akka.NET dependency is available

Enhances LoggerFactoryLogger to leverage Akka.NET's new semantic logging
APIs introduced in version 1.5.56. This change enables Microsoft.Extensions
.Logging (MEL) to receive full structured logging context with proper state
dictionaries instead of pre-formatted strings.

Changes:
- Completely rewrote LoggerFactoryLogger.Log() method to use semantic logging
- Extracts structured properties into MEL state dictionary
- Adds {OriginalFormat} key per MEL convention for template preservation
- Includes Akka metadata (ActorPath, Timestamp, Thread, LogSource)
- Added comprehensive test suite (SemanticLoggingSpecs.cs) with 7 tests covering:
  * Named and positional template properties
  * Multiple properties handling
  * Akka metadata preservation
  * {OriginalFormat} key verification
  * Format specifiers handling
  * Empty properties handling

All existing tests pass (457/458, 1 skipped - same as before).

## Impact
MEL sinks (Serilog, Seq, Application Insights, etc.) now receive properly
structured state dictionaries, enabling:
- Query by structured property values
- Correlation across log entries
- Rich dashboard visualizations
- Better log analysis and filtering

Example MEL state dictionary:
{
  "UserId": 12345,
  "Email": "[email protected]",
  "ActorPath": "akka://sys/user/myactor",
  "Timestamp": <DateTime>,
  "Thread": 17,
  "LogSource": "MyActor",
  "{OriginalFormat}": "User {UserId} with email {Email} logged in"
}

Depends on: Akka.NET >= 1.5.56
- Replaced all 7 instances of await Task.Delay(500) with AwaitAssertAsync()
- Added AwaitAssertAsync helper method that implements retry pattern for assertions
- Fixes anti-pattern of using arbitrary delays in async tests
- Tests now properly wait for conditions to be met rather than hoping 500ms is enough
- Updated Akka.NET dependency from 1.5.55 to 1.5.56
- Required for semantic logging API support
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.

1 participant