Vostok.Logging
HomeQuickstartModulesImplementations
1.0.0
1.0.0
  • Home
  • Quickstart
  • Guarantees
  • Configuration
  • Concepts and basics
    • Log interface
    • Log events
    • Syntax
      • Logging extensions
      • Message templates
      • Providing property values
    • Formatting
      • Output templates
      • Special properties
      • Format specifiers
    • Source context
    • Operation context
  • Modules
    • Abstractions
    • Configuration
    • Formatting
    • Console
    • File
    • Hercules
    • Context
    • Serilog
    • Log4net
    • NUnit
    • Microsoft
  • Implementations
    • Silent log
    • Console log
    • File log
    • Hercules log
  • Integrations
    • Serilog integration
    • Log4net integration
    • Microsoft logging integration
  • How-to guides
    • Using operation context
    • Using static log provider
    • Filtering events
    • Enriching events
    • Transforming events
    • Combining multiple logs
    • Custom output templates
    • External configuration rules
Powered by GitBook
On this page
  • Enriching from constant values
  • Enriching from dynamic values
  • Enriching from flowing context
  1. How-to guides

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();
PreviousFiltering eventsNextTransforming events

Last updated 6 years ago