Debugging using code


◷ Reading Time: 2 minutes

Using Events

The other way of debugging your rules is by using some events and internal methods that are provided by all engines. All of the following engines derive from a base class called ActiveElementEngine that provides some base events and methods to enable you to track the execution of rules:

  1. Procedural
  2. Validation
  3. Flow
  4. Decision
  5. Workflow

The following events give you the ability to monitor the execution of rules:

/// <summary>
/// When element is executing
/// </summary>
public event EventHandler<ActiveElementExecutionEventArgs> ActiveElementExecuting;
/// <summary>
/// When element execution is finished
/// </summary>
public event EventHandler<ActiveElementExecutionEventArgs> ActiveElementExecuted;
/// <summary>
/// When executor passes an element
/// </summary>
public event EventHandler<ActiveElementExecutionEventArgs> ActiveElementItemOutOfScope;
/// <summary>
/// When element is reached
/// </summary>
public event EventHandler<ActiveElementExecutionEventArgs> ActiveElementItemTracing;

If you are writing a unit test, console application, or any sort of sample application that consumes your rules, then you can handle these events and start logging and debugging execution by putting a break point on these event handlers.

Also, the other way of putting a breakpoint inside your rules is using the ‘System.Diagnostics.Debugger.Break()’ method. You can simply use Using to import these into your rules and call the ‘Break’ method to attach your rules to the debugger when required.

    <Using path="System.Diagnostics.Debugger"/>
Updated on June 6, 2019

Was this article helpful?

Related Articles