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
  1. How-to guides

Using operation context

PreviousHow-to guidesNextUsing static log provider

Last updated 6 years ago

This page lists preparation steps required to begin using in application logs.

Prerequisites: install , read section.

Step 1: enable operation context on a log instance using WithOperationContext() extension:

log = log.WithOperationContext();

Step 2: define context scopes by constructing and disposing OperationContextTokens:

using (new OperationContextToken("op1")) 
{
    // log something
    using (new OperationContextToken("op2")
    {
        // log something
    }
}

There's also an ILog extension named ForOperationContext which is just a convenient shortcut for creating OperationContextTokens and does not really depend on an ILog instance:

using (log.ForOperationContext("op")) { }
operation context
context module
operation context