Link Search Menu Expand Document

TraceLog


A trace-logging class that is used when executing an operation. It provides vital information of the actual execution via the ITrace object.

Properties

Below is the list of properties.

NameDescription
SessionIdHandles the identifier of the trace execution.
KeyHandles the key of the of the actual execution. By default, the value is the name of the operation that is being executed.

Tracing

All methods of the ITrace interface is using this class. You can debug to any method of the ITrace-based classes to trace the actual execution information.

Let us say you have a custom trace class named MyCustomTrace. Then, you pass this object when you call the Insert operation.

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

Then, you can set a breakpoint at your MyCustomTrace.BeforeExecution() method and see the actual trace information before the actual execution via CancellableTraceLog argument.

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

Also, you can set a breakpoint at your MyCustomTrace.AfterExecution() method and see the actual trace information after the insert operation.

public void AfterExecution<TResult>(ResultTraceLog<TResult> log)
{
    Console.WriteLine($"AfterExecution: {log.Statement}, TotalTime: {log.ExecutionTime.TotalSeconds} second(s)");
}

You can do the same in all operational method of the ITrace-based classes.