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: README.md
+19-25Lines changed: 19 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,7 +315,7 @@ Some Serilog packages require a reference to a logger configuration object. The
315
315
316
316
### Destructuring
317
317
318
-
Destructuring means extracting pieces of information from an object and create properties with values; Serilog offers the [@ destructuring operator](https://github.com/serilog/serilog/wiki/Structured-Data#preserving-object-structure). In case there is a need to customize the way log events are serialized (e.g., hide property values or replace them with something else), one can define several destructuring policies, like this:
318
+
Destructuring means extracting pieces of information from an object and create properties with values; Serilog offers the `@` [structure-capturing operator](https://github.com/serilog/serilog/wiki/Structured-Data#preserving-object-structure). In case there is a need to customize the way log events are serialized (e.g., hide property values or replace them with something else), one can define several destructuring policies, like this:
319
319
320
320
```yaml
321
321
"Destructure": [
@@ -343,35 +343,29 @@ Destructuring means extracting pieces of information from an object and create p
343
343
This is how the first destructuring policy would look like:
344
344
345
345
```csharp
346
-
namespace MyFirstNamespace
347
-
{
348
-
public class MyDto
349
-
{
350
-
public int Id {get; set;}
351
-
public int Name {get; set;}
352
-
}
346
+
namespace MyFirstNamespace;
353
347
354
-
public class FirstDestructuringPolicy : IDestructuringPolicy
355
-
{
356
-
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
357
-
{
358
-
result = null;
359
-
MyDto dto = value as MyDto;
348
+
public record MyDto(int Id, int Name);
360
349
361
-
if (dto == null)
362
-
{
363
-
return false;
364
-
}
350
+
public class FirstDestructuringPolicy : IDestructuringPolicy
351
+
{
352
+
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory,
353
+
[NotNullWhen(true)] out LogEventPropertyValue? result)
354
+
{
355
+
if (value is not MyDto dto)
356
+
{
357
+
result = null;
358
+
return false;
359
+
}
365
360
366
-
result = new StructureValue(new List<LogEventProperty>
367
-
{
368
-
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
369
-
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
370
-
});
361
+
result = new StructureValue(new List<LogEventProperty>
362
+
{
363
+
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
364
+
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
0 commit comments