-
Notifications
You must be signed in to change notification settings - Fork 7
AI Method 2
Ahmad Sattar edited this page Oct 24, 2019
·
8 revisions
Example configuration can be found here.
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 is formed in AI.
We keep correlation of each trace item, but add a visual representation of our traces.
The timeline and logs would look like this:

Start by adding AI to your project and build, explained here.
- Copy DGTracingService and IDGTracingService into your plugins project (find it here under the Services folder)
- Insert your instrumentation key at the top of DGTracingService
- It is also possible to fetch the instrumentation key with the
OrganizationServicethat resides in theLocalPluginContextconstructor step 4 uses
- It is also possible to fetch the instrumentation key with the
- Inside
Plugin.csAdd the following attribute above theLocalPluginContextconstructor
internal IDGTracingService DGTracingService {
get;
private set;
}- Inside
Plugin.cssLocalPluginContextconstructor below line containingthis.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));add
this.TracingService = new DGTracingService(this.TracingService, this.PluginExecutionContext.CorrelationId);
this.DGTracingService = (IDGTracingService)this.TracingService;- Add the following before the Try block in the
Executefunction insidePlugin.cs
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();- Inside the Catch section of the Try/Catch/Finally section add this to the top
timer.Stop();
localcontext.DGTracingService.TraceException(e);- Inside the finally section of the Try/Catch/Finally section add this to the top
timer.Stop();
localcontext.DGTracingService.TraceDependency(
localcontext.PluginExecutionContext.MessageName,
localcontext.PluginExecutionContext.PrimaryEntityName,
this.ChildClassName,
startTime, timer.Elapsed);- If you wish to show trace class names without namespace, add the following attribute above the
Pluginconstructor
protected string ChildClassNameSimple{
get;
private set;
}And add this inside the Plugin constructor
this.ChildClassNameSimple = childClass.Name;