The Problem SolverWIndows Workflow Foundation
HomeShow ChangesPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename

Search

History

19-10-2006 17:34:4319-10-2006 17:23:36

List all versions

Tracing Rule Set
.
Summary
One of the problems with RuleSets is tracing what rules are firing, when and why.

The PolicyActivity is rather cool but with more than a few rules in the RuleSet and full chaining enabled it can become a bit hard to see what is going on. Now it would be nice if we could step through the rules with the debugger but if there is a way I haven't found it yet. Of course you could add Console.WriteLine statements to the actions, after all they can be multiple statements. There is however an easier way that will show exactly what the runtime engine is doing and that is tracing.

Add the following to the app.config:

  <system.diagnostics>
    <switches>
      <add name="System.Workflow.Activities.Rules" value="Verbose" />
    </switches>
  </system.diagnostics>

And run the workflow again. This time the Immediate Window will contain a trace with all rules being loaded and their dependencies. After that the trace will contain all evaluations of conditions and results thereof. The following is an example of a small RuleSet I created:

System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "+5%" Condition dependency: "this/amount/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "+5%" THEN side-effect: "this/rate/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "10%" Condition dependency: "this/age/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "10%" THEN side-effect: "this/rate/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "50%" Condition dependency: "this/age/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "50%" THEN side-effect: "this/rate/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" Condition dependency: "this/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" Condition dependency: "this/amount/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" Condition dependency: "this/rate/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" Condition dependency: "this/discount/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" THEN side-effect: "this/discount/"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "+5%" THEN actions trigger rule "Calc"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "10%" THEN actions trigger rule "Calc"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "50%" THEN actions trigger rule "Calc"
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" THEN actions trigger rule "Calc"
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Executing
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating condition on rule "+5%".
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "+5%" condition evaluated to True.
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating THEN actions for rule "+5%".
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating condition on rule "10%".
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "10%" condition evaluated to True.
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating THEN actions for rule "10%".
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating condition on rule "50%".
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "50%" condition evaluated to True.
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating THEN actions for rule "50%".
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating condition on rule "Calc".
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" condition evaluated to True.
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating THEN actions for rule "Calc".
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" side effects enable rule "Calc" reevaluation.
System.Workflow.Activities.Rules Verbose: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Evaluating condition on rule "Calc".
System.Workflow.Activities.Rules Information: 0 : Rule Set "Rule Set1": InstanceId 4c453688-cb02-41e9-a641-39921711d2a0: Rule "Calc" condition evaluated to False.

Rather nice as you can see exactly what is going on. Just make sure you name your rules well otherwise it will still be somewhat hard to follow.

Enjoy!

Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics

  • TracingRuleSet