LogTracer

Tracer that dumps recorded traces to a logger.

Inherits: IReconfigurable, IReferenceable, ITracer

Description

The LogTracer class allows you to create a tracer that dumps recorded traces to a logger.

Configuration parameters

options:

  • log_level: log level to record traces (default: debug)

References

  • *:logger:*:*:1.0 - ILogger components to dump the captured counters
  • *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify counters source

Instance methods

BeginTrace

Begings recording an operation trace.

public TraceTiming BeginTrace(string correlationId, string component, string operation)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • component: string - name of the called component
  • operation: string - name of the executed operation.
  • return: TraceTiming - trace timing object.

Configure

Configures a component by passing its configuration parameters.

public void Configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

Failure

Records an operation failure with its name, duration and error

public void Failure(string correlationId, string component, string operation, Exception error, long duration)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • component: string - name of the called component
  • operation: string - name of the executed operation.
  • error: Exception - error object associated with this trace.
  • duration: long - execution duration in milliseconds.

SetReferences

Sets references to dependent components.

public void SetReferences(IReferences references)

  • references: IReferences - references to locate the component’s dependencies.

Trace

Records an operation trace with its name and duration.

public void Trace(string correlationId, string component, string operation, long duration)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • component: string - name of the called component
  • operation: string - name of the executed operation.
  • duration: long - execution duration in milliseconds.

Examples

var tracer = new LogTracer();
tracer.SetReferences(References.FromTuples(
    new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger()
));
var timing = trcer.BeginTrace("123", "mycomponent", "mymethod");
try {
    ...
    timing.EndTrace();
} catch
{
    timing.EndFailure(err);
}

See also