Plug-in Trace Logs outside the Sandbox


While I was doing some investigation for another blog article, I wanted to produce some Plug-in Trace Logs for a plug-in that was not running in the sandbox. It wasn't working, so as The Hosk says, I started by looking in the SDK socumentation for Plug-in Trace Logs. The documentation contains the following sentence that seems to indicate that it should work:

Tracing is supported for sandboxed (partial trust) and full trust registered custom code and during synchronous or asynchronous execution.

Nonetheless, it wasn't working and I wasn't the only person who was having the same problem.

Where next?

Having found nothing on the internet to indicate why this was happening, I decided to investigate further, which I did by firing up ILSpy and taking a peek into the CRM SDK DLLs. To cut a long story short, plug-in execution is controlled by the method Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal() (which resides in the Microsoft.Crm.ObjectModel.dll).

In the sandbox

For a sandboxed plug-in, the V5PluginProxyStep.ExecuteInternal() method eventually ends up calling the class/method called Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute() (in Microsoft.Crm.Sandbox.Client.dll). It's a long method, but the key lines are here, where it calls the method to create the plug-in trace log record.

if (flag2 && !string.IsNullOrWhiteSpace(sandboxExecutionContext.TraceInfo)) { this.CreatePluginTraceLogRecord(context, utcNow, sandboxExecutionContext.TraceInfo, string.Empty);

Outside the sandbox

For a non-sandboxed plug-in, the V5PluginProxyStep.ExecuteInternal() method just calls the Execute() method of your plug-in directly. It makes no attempt to create a trace log record.


I am taking this a proof that the platform is not going to create plug-in trace logs unless your plug-in is in the sandbox. It's not just that we have missed out an important piece of system configuration.

It is perplexing that the SDK documentation seems to indicate that it should work. I can only assume that it is referring to the feature where, if a plug-in throws an exception, the exception details are shown to the user in a dialog box (if they click to download the log file). The exception details will include any tracing that your plug-in has performed. This feature works just fine with non-sandboxed plug-ins.

To find out how to work around this problem, see my other article How to write Plug-in Trace Logs outside the sand box.

Post image Sand Toys copyright kathryn (license)