Class LogEventExtensions
Extension methods for accessing semantic logging properties from LogEvent instances. These methods make it easy for custom logger implementations to extract structured properties.
Inherited Members
Namespace: Akka.Event
Assembly: Akka.dll
Syntax
public static class LogEventExtensions
Methods
| Edit this page View SourceGetParameters(LogEvent)
Gets the parameter values from the log message. Returns empty enumerable if message is a pre-formatted string.
Declaration
public static IEnumerable<object> GetParameters(this LogEvent evt)
Parameters
| Type | Name | Description |
|---|---|---|
| LogEvent | evt | The log event |
Returns
| Type | Description |
|---|---|
| IEnumerable<object> | Parameter values, or empty enumerable |
Examples
var parameters = logEvent.GetParameters().ToArray();
// For log.Info("User {0}", 123), returns [123]
|
Edit this page
View Source
GetPropertyNames(LogEvent)
Gets the property names from the log event's message template. Returns empty list if message is a pre-formatted string.
Declaration
public static IReadOnlyList<string> GetPropertyNames(this LogEvent evt)
Parameters
| Type | Name | Description |
|---|---|---|
| LogEvent | evt | The log event |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | List of property names, or empty list |
Examples
var names = logEvent.GetPropertyNames();
// For "User {UserId} logged in", returns ["UserId"]
|
Edit this page
View Source
GetTemplate(LogEvent)
Gets the message template format string from the log event.
Declaration
public static string GetTemplate(this LogEvent evt)
Parameters
| Type | Name | Description |
|---|---|---|
| LogEvent | evt | The log event |
Returns
| Type | Description |
|---|---|
| string | Template string if LogMessage, otherwise the string representation |
Examples
var template = logEvent.GetTemplate();
// For semantic logs, returns "User {UserId} logged in"
// For pre-formatted strings, returns the actual message
|
Edit this page
View Source
TryGetProperties(LogEvent, out IReadOnlyDictionary<string, object>?)
Attempts to extract structured properties from the log event message.
Declaration
public static bool TryGetProperties(this LogEvent evt, out IReadOnlyDictionary<string, object>? properties)
Parameters
| Type | Name | Description |
|---|---|---|
| LogEvent | evt | The log event |
| IReadOnlyDictionary<string, object> | properties | The extracted properties dictionary (if successful) |
Returns
| Type | Description |
|---|---|
| bool | True if properties were extracted, false if message is a pre-formatted string |
Examples
if (logEvent.TryGetProperties(out var properties))
{
// Use structured properties with your native logger
foreach (var prop in properties)
{
Console.WriteLine($"{prop.Key} = {prop.Value}");
}
}
Edit this page