Link Search Menu Expand Document

CancellableTraceLog


A trace-logging class used to cancel an ongoing operation. It is passed to all BeforeExecution methods of the ITrace object and derives from TraceLog.

Properties

NameDescription
IsCancelled`Indicates whether the operation has been cancelled.
IsThrowExceptionIndicates whether an exception will be thrown back to the caller upon cancellation.
ParameterThe execution parameters.
StatementThe SQL statement generated by the library.

Methods

NameDescription
CancelCancels the operation. The throwException argument controls whether an exception is propagated to the caller.

Implementation

Pass a custom trace object when calling an operation such as Insert.

using (var connection = new SqlConnection(connectionString))
{
    connection.Insert<Person>(person, trace: new MyCustomTrace());
}

In the BeforeExecution() method, call Cancel() to abort the operation.

public void BeforeExecution(CancellableTraceLog log)
{
    if (log.Statement.IndexOf("INSERT") <= 0)
    {
        log.Cancel(true);
    }
}

Setting throwException to true causes an exception to be thrown back to the caller.