Monday, 11 May 2015

CRM 2015 Update 1 - Plugin Trace Log

Hi,

In the earlier vesions of CRM, we used to use ITracingService for tracing the plugin errors and that information is shown in System Jobs.

With the new release of CRM 2015 Update, we can configure CRM to write trace logs to CRM new entity and can be viewed in CRM. By default, CRM Administrators has the permission to view the logs.

Trace logs will only be written to the trace log entities if the plug-in developer uses tracing within the plug-in.

How to Enable Plugin Trace Log
  1. In the CRM Web application, navigate to Settings à Administration
  2. Select System Settings à Customization on the Administration page
  3. In the setting for Plug-In and Custom Workflow Activity Tracking choose one of the below options:
    • Off (default): feature turned off
    • Exceptions: the trace logs will be written to the CRM entities only if the developer returns the exception back to the user.
    • All: the trace logs will be written to the CRM entities whenever the plugin/workflow code is run, regardless of whether an exception is returned.
  4. Click OK to save the settings
 After you enable the feature, we should be able to see the logs in CRM.

View Logs

In the CRM, select Settings and under the Customizations menu, select Plug-In Trace Logs.


Now let us see it more in depth by creating a plugin.

Here is my plugin code.

public void Execute(IServiceProvider serviceProvider)
{
    try
    {
         IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext));
         IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
         IOrganizationService service = factory.CreateOrganizationService(context.UserId);
         ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                tracingService.Trace("Trace Start Check");
                throw new Exception("Exception Thrown");
   }
   catch (Exception ex)
   {
 
   }
}

I have registered the plugin on Account update


Opened an account record and updated it. The system has records in Plugin Trace Log and here are the details.




--
Happy CRM'ing
Gopinath 

No comments:

Post a Comment