Skip to content

Commit

Permalink
Fix issues spotted during code review
Browse files Browse the repository at this point in the history
  • Loading branch information
satrapu committed Aug 29, 2023
1 parent bc21976 commit 852b74a
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Some Serilog packages require a reference to a logger configuration object. The

### Destructuring

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

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

```csharp
namespace MyFirstNamespace
{
public class MyDto
{
public int Id {get; set;}
public int Name {get; set;}
}
namespace MyFirstNamespace;
public class FirstDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
{
result = null;
MyDto dto = value as MyDto;
public record MyDto(int Id, int Name);
if (dto == null)
{
return false;
}
public class FirstDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory,
[NotNullWhen(true)] out LogEventPropertyValue? result)
{
if (value is not MyDto dto)
{
result = null;
return false;
}
result = new StructureValue(new List<LogEventProperty>
{
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
});
result = new StructureValue(new List<LogEventProperty>
{
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
});
return true;
return true;
}
}
}
```

Expand Down

0 comments on commit 852b74a

Please sign in to comment.