During plug-in development, we need to troubleshoot our plug-in code for different errors that we may face during execution of the code. It is always a good practice to have your code well documented with proper exception handling. We can troubleshoot plug-in code in three ways:
ITracingService
service.
ITracingService
helps us to generate logging information that we may want to do at different steps. This is especially useful when we don't have debugging tools available and need logging information to troubleshoot our code. We can get ITracingService
from the service provider object as follows:
//Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
ITracingService
has one method Trace
that we can use to create logs as follows:
//adding log information tracingService.Trace("Logging Message");
All the tracing information generated in plug-ins can be accessed in the following ways:
Microsoft Dynamics CRMTrace
Plug-in tracing in CRM applications is not enabled by default; we need to enable it from the Customization tab by navigating to Settings | System Settings. Once this setting is enabled we can see tracing information in the CRM as follows:
We can also get tracing information into log files at the server level if tracing is enabled in the CRM server. To enable tracing in the CRM server you can refer to: https://technet.microsoft.com/en-us/library/hh699694.aspx#BKMKserver_level_tracing.
Debugging is the process where we execute our code line by line in order to identify runtime errors and fix them. We can debug both non-isolation and isolation plug-ins; in the case of non-isolation plug-ins, we need to copy the PDB and DLL files to the serverinassembly
folder on the CRM server and we need to attach the service process based on the plug-in type in Visual Studio. The following table presents the different services that we need to attach:
Plug-in Type |
Process Name |
---|---|
Online |
|
Offline |
|
Asynchronous plug-in and workflow |
|
You need to perform the following steps to debug your on-premise plug-in, where Visual Studio is installed on the CRM server:
PDB
and DLL
files in serverinassembly
.If Visual Studio is not installed on the CRM server then we need to use remote debugging. You can refer to https://community.dynamics.com/crm/b/zhongchenzhoustipstricksandportaldevelopment/archive/2012/05/16/dynamics-crm-remote-debugging-step-by-step for the steps required for remote debugging.
In the case of sandbox plug-ins, we need to copy the PDB
and DLL
files under serverinassembly
folder on the server running the sandbox worker process (the Sandbox Processing Service role server). In the case of the sandbox server, we need to attach Microsoft.Crm.Sandbox.WorkerProcess
for debugging.
We can also debug our plug-in using the plug-in registration tool; this is especially useful when you are working with CRM Online deployment. Please refer to: http://nishantrana.me/2014/07/02/debugging-online-plugin-in-crm-2013/.
18.217.136.144