Question

I've written a custom workflow activity against CRM 2013. You don't need to understand what it does. The problem I have is that despite instantiating the ITracingService, any tracing content that I generate using the Trace(...) method is obfuscated at runtime for real-time workflows only. In other words, if I run my workflow asynchronously and (deliberately) throw an Exception, I get to see the trace log in the corresponding system job record. If I simply switch the workflow to be "real-time" (synchronous) then I still get an exception and I still get any custom exception text, but of course there is no corresponding systemjob generated for realtime workflows so, like a plug-in, I am seeking my Trace output in the downloadable log file that is presented when an exception occurs. In this case, my Traces are not visible but I get what appears to be Microsoft's trace log from (perhaps) the parent context that hosts the workflow - you can see that it is referencing the steps in my workflow process definition:

[Microsoft.Crm.ObjectModel: Microsoft.Crm.Extensibility.InternalOperationPlugin]
[46f6cf4c-14ae-4f1e-98a1-eae99a37e95c: ExecuteWorkflow]
Starting sync workflow 'MyTestWorkflow', Id: ca8782b1-7ca4-e311-a055-6c3be5be5f78
Entering CreateStep1_step: 
Entering CustomActivityStep2_step: 
Sync workflow '__Test' terminated with error 'Unexpected exception from plug-in (Execute): My.Test.WF.DoSomething: System.NullReferenceException: Object reference not set to an instance of an object.'

In my assembly My.Test.WF.DoSomething I access the Tracing Service at invocation and immediately start writing via the Trace() method, e.g.

_trace.Trace("Starting Greg's custom code...");

This is only an example, but the point is, my tracing works when asynchronous but is "lost" when synchronous.

Any ideas?

Was it helpful?

Solution

The process sessions section on the corresponding workflow designer form contains the full exception message.

OTHER TIPS

The problem is that the full exception message does not contains the trace created through the ITracingService Trace method, just contains the exception that's been thrown by the platform, no user traces are included in the comments tab of the process section.

I think the best approach for development purpose is to use a StringBuilder instead of ITracingService and throw the exception using StringBuider.toString() as the message. As for production release, perhaps the best approach is to use a custom entity to trace the errors in runtime, or not use custom workflows activities on synchronous workflows at all.

Cheers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top