Enriching events

Enriching is a term used to denote adding external properties to log events after their construction. It allows to augment events with contextual information not available at immediate logging site.

Default implementations of source context and operation context 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.

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

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

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

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:

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

Enriching from dynamic values

Prerequisites: install abstractions module.

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

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

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

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

Enriching from flowing context

Prerequisites: install abstractions module and context module.

Extensions listed in this section allow to enrich log events with values from FlowingContext exposed from Vostok.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):

log = log.WithFlowingContextProperty("contextProperty", "logProperty");
  • Add the value of the global with following type from FlowingContext to incoming log events with specified name:

log = log.WithFlowingContextGlobal<CustomType>("logProperty");
  • Add all current properties from FlowingContext to incoming log events:

log = log.WithAllFlowingContextProperties();