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.