Skip to content

Commit 852b74a

Browse files
committed
Fix issues spotted during code review
1 parent bc21976 commit 852b74a

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

README.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ Some Serilog packages require a reference to a logger configuration object. The
315315

316316
### Destructuring
317317

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:
319319

320320
```yaml
321321
"Destructure": [
@@ -343,35 +343,29 @@ Destructuring means extracting pieces of information from an object and create p
343343
This is how the first destructuring policy would look like:
344344

345345
```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;
353347
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);
360349
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+
}
365360
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()))
365+
});
371366
372-
return true;
367+
return true;
373368
}
374-
}
375369
}
376370
```
377371

0 commit comments

Comments
 (0)