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
| Name | Description |
|---|---|
| IsCancelled` | Indicates whether the operation has been cancelled. |
| IsThrowException | Indicates whether an exception will be thrown back to the caller upon cancellation. |
| Parameter | The execution parameters. |
| Statement | The SQL statement generated by the library. |
Methods
| Name | Description |
|---|---|
| Cancel | Cancels 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
throwExceptiontotruecauses an exception to be thrown back to the caller.