Skip to content

Commit 0f3cfcc

Browse files
committed
add aspnet, simple and start aot
1 parent 3b4f5ee commit 0f3cfcc

File tree

4 files changed

+1034
-69
lines changed

4 files changed

+1034
-69
lines changed

docs/core/logging-v2.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,65 @@ The logging utility provides a Lambda optimized logger with output structured as
3333
| Amazon.Lambda.Serialization.SystemTextJson | 2.4.3 | 2.4.4 | dotnet add package Amazon.Lambda.Serialization.SystemTextJson |
3434
| Microsoft.Extensions.DependencyInjection | 8.0.0 | 8.0.1 | dotnet add package Microsoft.Extensions.DependencyInjection |
3535

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+
3695
## Installation
3796

3897
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:
244303
**SamplingRate** | int | 0.1 | Debug logging sampling rate in percentage e.g. 10% in this case
245304
**Customer Keys** | | |
246305

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+
247309
## Message templates
248310

249311
You can use message templates to extract properties from your objects and log them as structured data.

0 commit comments

Comments
 (0)