Using operation context
Step 1: enable operation context on a log instance using
WithOperationContext()
extension:log = log.WithOperationContext();
Step 2: define context scopes by constructing and disposing
OperationContextToken
s: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:using (log.ForOperationContext("op")) { }
Last modified 3yr ago