Prerequisites: none
Namespaces: InRule.Runtime, InRule.Runtime.Tracing.Events, InRule.Runtime.Tracing.Frames
Classes: FileSystemRuleApplicationReference, RuleSession, Entity
See Also: Working with the Trace Viewer through irSDK, Basic Example of Calling the Rule Engine, Creating a RuleSession, Creating Entities
The following code sample shows methods to extract rule tracing output to various *.ruletrace and *.xml formats. The *.ruletrace files can be opened directly in irAuthor so that trace data can be evaluated in the trace viewer.
Tracing is enabled by setting the LogOptions Property to EngineLogOptions.RuleTrace.
During execution, a temporary file is used to persist tracing data. This file is cleaned up by the Dispose method on the RuleSession. However, copies of the file can be persisted using the WriteExportTrace method as shown in the example below.
RuleApplicationReference ruleAppRef = new FileSystemRuleApplicationReference(@"C:\RuleApps\MortgageCalculator.ruleapp");
using (var session = new RuleSession(ruleAppRef))
{
session.Settings.LogOptions = EngineLogOptions.RuleTrace;
var mortgageEntity = session.CreateEntity("Mortgage");
mortgageEntity.LoadXml(@"C:\RuleApps\Mortgage.xml");
RuleExecutionLog log = null;
try
{
// Temp files are created for session during apply/execute rules, cleaned on dispose of session
log = session.ApplyRules();
}
catch (RuntimeException ex)
{
// In the event of an error, the execution trace can still be retrieved from the RuntimeException
log = ex.Log;
}
// Copies of trace files are generated when trace is created during GetExecutionTrace, and cleaned on
dispose of trace.
// Make sure the IExecutionTrace is disposed, so trace files are cleaned up
using (var trace = log.GetExecutionTrace())
{
// Writes out a complete "rule trace" package that includes the rule application and trace data.
// This *.ruletrace file can be opened in irAuthor
trace.WriteExportPackage(@"C:\temp\mylog.ruletrace");
// Write out the trace frame XML
trace.WriteXml(@"C:\temp\mylog.frames.xml", new TraceFrameXmlWriterSettings());
// Write out the events XML
trace.EventReader.GetAllEvents().WriteXml(@"C:\temp\mylog.events.xml", new TraceEventXmlWriterSettings());
// Write out events in a tab-delimited format that can be viewed in Excel
trace.EventReader.GetAllEvents().WriteTabDelimited(@"C:\temp\mylog.events.txt"); // same as
clipboard
// Get only specific types of events
// Processed as a "SQL LIKE statement"
trace.EventReader.GetFilteredEvents("filtertext").WriteXml(@"C:\temp\myfilteredlog.events.xml",
new TraceEventXmlWriterSettings());
// Retrieve a "page" of event data
var firstPage = trace.EventReader.GetAllEvents().GetEventPage(1, 100);
}
}
// Rule execution trace can be populated from a previously persisted file
var executionTrace = ExecutionTrace.Load(@"C:\temp\mylog.ruletrace");
Comments
0 comments
Please sign in to leave a comment.