The out of box Plugin Tracing introduced in CRM 2015 SP1 has made tracing plugins within Microsoft Dynamics 365 for Customer Engagement a much more streamlined process. Being able to control what is logged from a system level (nothing, exceptions only, or all) also helps to ensure you only are only incurring the cost of logging when desired.

Unfortunately, there is no support out of the box for enabling/disabling tracing at a plugin specific level. This becomes even more apparent when developers are trying to troubleshoot a plugin and haven’t added any additional logging. Normally this requires the developer to make additional logging calls in the plugin; recompile, redeploy, and retest, and then go back and remove the additional logging when the cause and fix have been determined. Not only is this extremely time intensive, it really isn’t an option for troubleshooting an issue in production.

A simple solution to this problem is to utilize a base plugin class for all plugins that conditionally logs the plugin context based on information in the Secure Configuration of the plugin registration. The result is if additional logging is desired for a particular plugin, you can enable/disable it via the plugin registration, without having to recompile, or redeploy code! The Secure Configuration is used since it isn’t migrated with solutions, so if you have the additional logging enabled in one environment, extracting the registration step via a solution and importing it into another environment will not affect tracing.

Below is a sample plugin base class that will trace the plugin context pre-plugin execution if “PluginBase.TracePreContext” is found in the Secure Configuration, and the context post-plugin execution if “PluginBase.TracePostContext” is found in the Secure Configuration, and both if “PluginBase.TraceContext” is found.

plugin plugin

There you have it! Subscribe to our blog for more helpful tips and tricks!

Happy Dynamics 365’ing!

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.