Skip to content

AI Method 2

Ahmad Sattar edited this page Oct 24, 2019 · 8 revisions

2. Traces, exceptions and plugin execution as dependencies

The second method of logging extends on the first by timing each execution and tracking them as dependencies, such that a timeline of plugin execution if formed in AI. We keep correlation of each trace item, but add a visual representation to our traces.
The timeline and logs would look like this: Trace timeline of method 2 Trace logs of method 2

Setting it up

  1. Copy the DGTracingService and IDGTracingService into your plugins project
  2. Insert your instrumentation key at the top of DGTracingService
  3. Inside Plugin.cs Add the following attribute above the LocalPluginContext constructor
internal IDGTracingService DGTracingService {
    get;

    private set;
}
  1. Inside Plugin.cs Below line containing this.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); add
this.TracingService = new DGTracingService(this.TracingService, this.PluginExecutionContext.CorrelationId);
this.DGTracingService = (IDGTracingService)this.TracingService;
  1. Add the following before the Try block in the Execute function inside Plugin.cs
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();
  1. Inside the Catch section of the Try/Catch/Finally secion add this to the top
timer.Stop();
localcontext.DGTracingService.TraceException(e);
  1. Inside the finally section of the Try/Catch/Finally secion add this to the top
timer.Stop();
localcontext.DGTracingService.TraceDependency(
    localcontext.PluginExecutionContext.MessageName,
    localcontext.PluginExecutionContext.PrimaryEntityName, 
    this.ChildClassName,
    startTime, timer.Elapsed);
  1. If you wish to show trace class names without namespace, add the following attribute above the Plugin constructor
protected string ChildClassNameSimple{
    get;
    private set;
}

And add this inside the Plugin constructor

this.ChildClassNameSimple = childClass.Name;
Clone this wiki locally