> For the complete documentation index, see [llms.txt](https://vostok.gitbook.io/logging/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vostok.gitbook.io/logging/how-to-guides/enriching-events-with-custom-properties.md).

# Enriching events

*Enriching* is a term used to denote adding external properties to [log events](/logging/concepts/log-events.md) after their construction. It allows to augment events with contextual information not available at immediate logging site.&#x20;

Default implementations of [source context](/logging/concepts/source-context.md) and [operation context](/logging/concepts/operation-context.md) involve enrichment of log events with special well-known properties.

By default, enrichment extensions do not overwrite properties already present in log events, although this behaviour can be configured.

### Enriching from constant values

**Prerequisites**: install [abstractions module](/logging/modules/abstractions.md).

Add a property with given name and value to incoming log events without overwriting existing values:

```csharp
log = log.WithProperty("env", "dev");
```

Add given properties to incoming log events, potentially overwriting existing values:

```csharp
log = log.WithProperties(
    new Dictionary<string, object>
    {
        ["env"] = "dev",
        ["host"] = "vm-app"
    }, 
    allowOverwrite: true);
```

Add all public properties of given object to incoming log events:

```csharp
log = log.WithObjectProperties(new {Prop1 = 1, Prop2 = 2});
```

### Enriching from dynamic values

**Prerequisites**: install [abstractions module](/logging/modules/abstractions.md).

Add a property with given key and value provided by given delegate to incoming log events:

```csharp
log = log.WithProperty("dynamicProperty", () => GetPropertyValue());
```

Add all public properties of the object provided by given delegate to incoming log events:

```csharp
log = log.WithObjectProperties<CustomType>(() => GetCustomValue());
```

### Enriching from flowing context

**Prerequisites**: install [abstractions module](/logging/modules/abstractions.md) and [context module](/logging/modules/context.md).

Extensions listed in this section allow to enrich log events with values from `FlowingContext` exposed from [Vostok.Context](https://vostok.gitbook.io/context) library:

* Add the value of the property with given name from `FlowingContext` to incoming log events with specified log name (which may differ from property name in context):

```csharp
log = log.WithFlowingContextProperty("contextProperty", "logProperty");
```

* Add the value of the global with following type from `FlowingContext` to incoming log events with specified name:

```csharp
log = log.WithFlowingContextGlobal<CustomType>("logProperty");
```

* Add all current properties from `FlowingContext` to incoming log events:

```csharp
log = log.WithAllFlowingContextProperties();
```
