コード例 #1
0
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull((object)ruleContext, "ruleContext");
            LoggerRuleContext loggerRuleContext = ruleContext as LoggerRuleContext;

            if (loggerRuleContext == null)
            {
                return(false);
            }
            return(Compare(loggerRuleContext.LogText, logText) && MeetsThreshold(loggerRuleContext));
        }
コード例 #2
0
        public override void Apply(T ruleContext)
        {
            var makerKey  = ItemUtil.GetItemById(IftttAccountId)?[Templates.Account.Fields.MakerKey];
            var eventName = ItemUtil.GetItemById(IftttEventId)?[Templates.Event.Fields.EventName];
            LoggerRuleContext loggerRuleContext = ruleContext as LoggerRuleContext;

            if (loggerRuleContext == null)
            {
                return;
            }
            var value1 = loggerRuleContext.LogText + " was written in logs " + loggerRuleContext.Threshold + " times";

            var iftttService = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService <IIftttService>();

            iftttService.Trigger(makerKey, eventName, value1);
        }
コード例 #3
0
        /// <summary>
        /// Each log condition have threshold that it needs to meet, for example a specific log message should get written x number of times before triggering the action
        /// </summary>
        /// <param name="loggerRuleContext"></param>
        /// <returns></returns>
        private bool MeetsThreshold(LoggerRuleContext loggerRuleContext)
        {
            string thresholdKey = loggerRuleContext.ItemId.ToString() + logCount;

            if (Variables.LogsThreshold == null)
            {
                Variables.LogsThreshold = new Dictionary <string, int>();
            }
            if (Variables.LogsThreshold.ContainsKey(thresholdKey))
            {
                if (Variables.LogsThreshold[thresholdKey] > logCount)
                {
                    Variables.LogsThreshold[thresholdKey] = 0;
                    loggerRuleContext.Threshold           = logCount;
                    return(true);
                }
                Variables.LogsThreshold[thresholdKey]++;
            }
            else
            {
                Variables.LogsThreshold.Add(thresholdKey, 1);
            }
            return(false);
        }