You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/logging.md
+118-3Lines changed: 118 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -604,10 +604,125 @@ You can remove any additional key from entry using `Logger.RemoveKeys()`.
604
604
}
605
605
```
606
606
607
-
##Extra Keys
607
+
### Temporary keys with ExtraKeys
608
608
609
-
Extra keys allow you to append additional keys to a log entry. Unlike `AppendKey`, extra keys will only apply to the
610
-
current log entry.
609
+
The `ExtraKeys` method allows temporary modification of the Logger's context without manual cleanup. It's useful for adding context keys to specific workflows while maintaining the logger's overall state.
610
+
611
+
Keys are automatically removed when the scope ends, eliminating the need to manually call `AppendKey` and `RemoveKeys`.
612
+
613
+
=== "Using Dictionary"
614
+
615
+
```c# hl_lines="12-16"
616
+
/**
617
+
* Handler for requests to Lambda function.
618
+
*/
619
+
public class Function
620
+
{
621
+
[Logging]
622
+
public async Task<APIGatewayProxyResponse> FunctionHandler
Use `ExtraKeys` when you need keys for a specific operation or code block. Use `AppendKey` when keys should persist for the entire Lambda invocation.
716
+
717
+
!!! warning "Key overwrite behavior"
718
+
If a key already exists when entering an `ExtraKeys` scope, it will be overwritten and then **removed** when the scope ends. The original value is not restored. Use unique key names within `ExtraKeys` scopes to avoid unexpected behavior.
719
+
720
+
!!! info "Async safe"
721
+
`ExtraKeys` is safe to use across `async/await` boundaries. Keys will correctly flow through asynchronous operations within the same execution context.
722
+
723
+
## Extra Keys (Single Log Entry)
724
+
725
+
Extra keys can also be added to a single log entry using message templates. Unlike `AppendKey` or `ExtraKeys()`, these keys will only apply to the current log entry.
611
726
612
727
Extra keys argument is available for all log levels' methods, as implemented in the standard logging library - e.g.
0 commit comments