Saturday, July 09, 2016

Tracing in Dynamics CRM Custom Assemblies


When writing custom assemblies for Dynamics CRM you can add  trace messages to your code to help track down problems and  identify performance issues. Trace messages can logged by initializing the tracing service in your code and calling the Trace method. I usually add the execution time as part of my trace messages especially when calling external services as this can be a performance pain point which may be difficult to track down.


ITracingService logger = (ITracingService)ServiceProvider.GetService(typeof(ITracingService));

logger.Trace(DateTime.Now.ToString("mm:ss:ffff") + ": Calling FX Rate");
this.callFxRest();
logger.Trace(DateTime.Now.ToString("mm:ss:ffff") + ": FX Rate");




If an exception is raised in a plugin the traces messages are included in the error text returned to the user.



To can view your trace logs you need to enable logging in System Settings -> Customizations. You can then select if you want tracing enabled just for Exceptions or All.

Once logging is enabled you go Settings -> Plug in Trace Log to see the logs files. Note that the log files are created asynchronously so there may be a slight delay for your log to appear after execution.



2 comments:

  1. Is it just me or has the "Plug-in Trace Log" disappeared from the site map in the latest CRM Online version (as of Aug 2016)?

    ReplyDelete
  2. Hi Eliot,

    I just started a new trial and it has not moved.
    Have you edited your sitemap? you can use xrmtoolbox to reset it
    hth
    Joe


    ReplyDelete