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

  • ExecutionTime - handles the total elapsed time of the actual execution.
  • Parameter - handles the parameters of the execution.
  • Result - handles the actual execution result.
  • Statement - handles the actual SQL statement generated by the library.

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.BeforeInsert() method and see the actual trace information before the actual execution via CancellableTraceLog argument.

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

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

public void AfterInsert(TraceLog log)
{
    Console.WriteLine($"AfterInsert: {log.Statement}, TotalTime: {log.ExecutionTime.TotalSeconds} second(s)");
}

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