Some customers asked how they can find information about what rules got executed and what was the condition evaluation result for these rules. The following details how you can accomplish this when rules execute in a workflow instance context or outside of a workflow instance.
In WF v1.0, if your rules are executing in a workflow context, you will get a user tracking event when rules execute. The user tracking event will have the rule name and the condition evaluation result. See the post here for how you can use WF’s OOB SqlTrackingService to track rules execution within a workflow.
When WF rules are executing outside of the workflow context, you can’t utilize the workflow runtime tracking services for rules tracking purposes. Alternatively you should use System.Diagnostic traces for this purpose. You will receive information about rules execution, including rules names, then and else-side effects, what rules executed and what the condition evaluation results for these rules are. Note, if your rules are executing within a workflow instance, you can still utilize the System.Diagnostic traces in a similar way to receive traces regarding your rules execution.
To demo this, I modified the Rules Driven UI sample, to log the rules trace information to a file. Alternatively, you can log this information to a database to later query on it. Simple steps to modify your similar application are below and the modified solution is attached.
You’ll get traces enables by editing the config file to add the following:
<add name=”System.Workflow.Activities.Rules” value=”All” />
You could change the value from All to verbose, or informational. See TraceLevel enumeration in the .NET Framework Class Library for more info.
Create a simple custom TraceListener
Add a FileTraceListener class (FileTraceListener.cs) to the project. FileTraceListener implements TraceListener. The FileTraceListener writes the trace output to a text file.
Add the file trace listener to the TraceListeners collection
To monitor the trace output using the custom trace listener, we need to add an instance of it to the TraceListers collection in Form1.cs as follows:
FileTraceListener fileTraceListener = new FileTraceListener(traceListenerFileName);
Notice a file UIRulesScenarioTraces.txt will be created, and appended when you run the application. The file will be in the same path as the UIRulesScenario.exe and the traces will be logged to it.