Enable plugin or custom workflow trace logs in MS Dynamics 365

Hi All,

Microsoft has introduced a new feature called Plugin Trace Log in Dynamics CRM 2016. In this blog we will see how to enable logs for Plugin and custom workflow. 

The following steps are to enable Plugin Trace Log in Dynamics CRM.

Login into D365 CRM with administrator > goto Settings area > select System Settings

In Customization tab we have an option set Enable logging to plug-in trace log





OFF:(Value is 0) Writing to the trace log is disabled. No PluginTraceLog records will be created. However, custom code can still call the Trace(String, Object[]) method even though no log is written.

Exception:(Value is 1) Trace information is written to the log if an exception is passed back to the platform from custom code.

ALL:(Value is 2) Trace information is written to the log upon code completion or an exception is passed back to the platform from the custom code.

Below is the code is used for log tracing service: 

//Extract the tracing service for use in debugging plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Use the tracing service tracingService.Trace("Write your message here.");

After enable the plugin trace logs
navigate to Dynamics 365 > Settings > Plug-in Trace Log
and search for the log records that are created by your plugin or custom workflow.

See the below screen 
Open the record and check the Message Block in the Execution Tab.
Above image shows the custom trace log.

Sample code plugin trace log is:

    public class PostCreateContact_TraceLogdemo : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory= (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

            ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracing.Trace("Trace Log fired: Contact created");
        }
    }


Try it once.

Thank you.

Best Regards,
Pavan Kumar K.

Comments

Popular posts from this blog

Working with Multi Select Option Set using C# in Dynamics 365.

Write a sample plugin and how to register a plugin.