Get complete trace through multiple level plugins



While extending MSD CRM with complicated business requirements, we write many plugins; one plugin triggers from another plugin’s create or update. In such a scenarios if one of child plugin breaks then it will provide only current plugins trace, it’s very hard to analyse that particular scenario or replicate that same scenario in Dev environment without the proper trace.  if we develop with normal plugin sample it won’t generates that all trace from various different plugins, it will provide only one plugin’s trace where it actually got a break. 

To get complete trace we need to add all inner trace to current plugin’s trace, Its dot net trick, so when it breaks it will generate the complete trace from its all parents plugins.

Well, here is sample plugin format to get the complete trace from all plugins …

public void Execute(IServiceProvider serviceProvider)


var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

var context = new CommonContext(serviceProvider, tracingService, true);

context.Trace(“BEGIN SamplePlugin”);




// Check if the InputParameters property bag contains a target

// of the current operation and that target is of type DynamicEntity.


if (context.PluginContext.PrimaryEntityName != “soft_EntityName”)


throw new InvalidPluginExecutionException(

$”Registered plugin on incorrect entity [{context.PluginContext.PrimaryEntityName}]”);


if (context.PluginContext.MessageName != “Update”)


throw new InvalidPluginExecutionException(

$”Registered plugin on incorrect message [{context.PluginContext.MessageName}]”);




//plugin logic

//goes here


context.Trace(“END SamplePlugin”);


catch (Exception ex)


var innerEx = ex.InnerException;

while (innerEx != null)



innerEx = innerEx.InnerException;



throw new InvalidPluginExecutionException(ex.Message, ex);





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s