TraceLog
A trace-logging class used during operation execution. It provides execution details via the ITrace object.
Properties
| Name | Description |
|---|---|
| SessionId | The identifier of the trace execution. |
| Key | The key of the execution. Defaults to the name of the operation being executed. |
Tracing
All methods of the ITrace interface use this class. Set breakpoints in ITrace-based class methods to inspect execution details.
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 BeforeExecution(), inspect or cancel the operation via the CancellableTraceLog argument.
public void BeforeExecution(CancellableTraceLog log)
{
Console.WriteLine($"BeforeExecution: {log.Statement}");
if (log.Statement.IndexOf("INSERT") <= 0)
{
log.Cancel(true);
}
}
In AfterExecution(), inspect the result after execution.
public void AfterExecution<TResult>(ResultTraceLog<TResult> log)
{
Console.WriteLine($"AfterExecution: {log.Statement}, TotalTime: {log.ExecutionTime.TotalSeconds} second(s)");
}
The same pattern applies to all operational methods of ITrace-based classes.