> 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/using-operation-context.md).

# Using operation context

This page lists preparation steps required to begin using [operation context](/logging/concepts/operation-context.md) in application logs.

**Prerequisites**: install [context module](/logging/modules/context.md), read [operation context](/logging/concepts/operation-context.md) section.

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

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

**Step 2**: define context scopes by constructing and disposing `OperationContextToken`s:

```csharp
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 `OperationContextToken`s and does not really depend on an `ILog` instance:

```csharp
using (log.ForOperationContext("op")) { }
```
