rf => rf.ReferenceB == myNameFact
and rf => rf.ReferenceB == otherNameFact
are the same. The reason the issue goes away as soon as you change or add expressions, is that the opportunity for node sharing goes away. I'm working on fixing it.
public class LogLevelRule : Rule
{
public static ILog Log = LogManager.GetLogger("MyLogger");
public override void Define()
{
string logLevel = default;
When()
.Query(() => logLevel, q => q
.From(() => GetCurrentLogLevel(Log)));
Then()
.Do(x => Console.WriteLine($"Logging at {logLevel} with {Log.Logger.Name}"));
}
private string GetCurrentLogLevel(ILog logger)
{
if(logger.IsDebugEnabled)
return "Debug";
if(logger.IsInfoEnabled)
return "Info";
if(logger.IsWarnEnabled)
return "Warn";
if(logger.IsErrorEnabled)
return "Error";
if(logger.IsFatalEnabled)
return "Fatal";
return "None";
}
}
We are planning on using NRules as an engine in a multi-tenant environment. As such, we would like to keep the rules repo (and the associated factories) separated. In the same process.
We would setup a dictionary of tenants and their associated rules repo/factory. When a fact is generated in the app, it would pass it to the process. We will search the dictionary for the tenant. We would then use the factory returned for the tenant to setup a session and process the fact.
Do you guys think there are any problems with this design?
We have a few hundred rules and we are logging RuleFired, RuleFiring, and others. We are logging everything and it is overwhelming, with thousands of events being captured. I am trying to see if there is a way that I could write some logic that captures the rules that fired for each session, captures the rule/rule info in an object, and after the last rule for that session runs can send that log.
Is there a way to tell when the rules sessions has started and is complete and will no longer be called until the next session?
Hi all, just getting started with NRules, and we're planning on using it as a constraint mechanism; basically a bunch of rules accept the same input, and I want to get a true/false that all succeeded, or find out that some rule failed. So, it's less about having side effects executed by each rule, but using the rules as a gatekeeper for the next logic I want to execute.
A naive approach would be to use Match to find data which does not fit the rule, and use Do to throw an exception. When I catch the exception, I can log it and return 'false'.
Obviously this isn't the optimal use of exceptions for logic, and I wanted to ask if there's a better approach I'm missing? I was looking for a way to pass back some state from each rule, and check this via the session after it had fired. Is that possible?