@@ -33,6 +33,65 @@ The logging utility provides a Lambda optimized logger with output structured as
33
33
| Amazon.Lambda.Serialization.SystemTextJson | 2.4.3 | 2.4.4 | dotnet add package Amazon.Lambda.Serialization.SystemTextJson |
34
34
| Microsoft.Extensions.DependencyInjection | 8.0.0 | 8.0.1 | dotnet add package Microsoft.Extensions.DependencyInjection |
35
35
36
+ #### Extra keys - Breaking change
37
+
38
+ In v1.x, the extra keys were added to the log entry as a dictionary. In v2.x, the extra keys are added to the log entry as
39
+ a JSON object.
40
+
41
+ There is no longer a method that accepts extra keys as first argument.
42
+
43
+ === "Before (v1)"
44
+
45
+ ```csharp
46
+ public class User
47
+ {
48
+ public string Name { get; set; }
49
+ public int Age { get; set; }
50
+ }
51
+
52
+ Logger.LogInformation<User>(user, "{Name} is {Age} years old",
53
+ new object[]{user.Name, user.Age});
54
+
55
+ var scopeKeys = new
56
+ {
57
+ PropOne = "Value 1",
58
+ PropTwo = "Value 2"
59
+ };
60
+ Logger.LogInformation(scopeKeys, "message");
61
+
62
+ ```
63
+
64
+ === "After (v2)"
65
+
66
+ ```csharp
67
+ public class User
68
+ {
69
+ public string Name { get; set; }
70
+ public int Age { get; set; }
71
+
72
+ public override string ToString()
73
+ {
74
+ return $"{Name} is {Age} years old";
75
+ }
76
+ }
77
+
78
+ // It uses the ToString() method of the object to log the message
79
+ // the extra keys are added because of the {@} in the message template
80
+ Logger.LogInformation("{@user}", user);
81
+
82
+ var scopeKeys = new
83
+ {
84
+ PropOne = "Value 1",
85
+ PropTwo = "Value 2"
86
+ };
87
+
88
+ // there is no longer a method that accepts extra keys as first argument.
89
+ Logger.LogInformation("{@keys}", scopeKeys);
90
+ ```
91
+
92
+ This change was made to improve the performance of the logger and to make it easier to work with the extra keys.
93
+
94
+
36
95
## Installation
37
96
38
97
Powertools for AWS Lambda (.NET) are available as NuGet packages. You can install the packages
@@ -244,6 +303,9 @@ Your logs will always include the following keys to your structured logging:
244
303
** SamplingRate** | int | 0.1 | Debug logging sampling rate in percentage e.g. 10% in this case
245
304
** Customer Keys** | | |
246
305
306
+ !!! Warning
307
+ If you emit a log message with a key that matches one of ` level ` , ` message ` , ` name ` , ` service ` , or ` timestamp ` , the Logger will ignore the key.
308
+
247
309
## Message templates
248
310
249
311
You can use message templates to extract properties from your objects and log them as structured data.
0 commit comments