Beispiel #1
0
        public void Push(LoggingItem loggingItem)
        {
            if (_rules == null)
            {
                var searchRules = _loggingRuleRepository.SearchAsync(x => x.IsEnabled).Result;

                if (searchRules.IsSuccessful && searchRules.Result != null)
                {
                    _rules = new ConcurrentBag <LoggingRule>(searchRules.Result);
                }
            }

            if (_rules == null)
            {
                return;
            }

            foreach (var rule in _rules)
            {
                if (Evaluate(rule, loggingItem))
                {
                    Notify(rule, loggingItem);
                }
            }
        }
Beispiel #2
0
        private bool Evaluate(LoggingRule rule, LoggingItem loggingItem)
        {
            var lambdaParser = new NReco.Linq.LambdaParser();
            var varContext   = new Dictionary <string, object> {
                ["LoggingItem"] = loggingItem, ["Warning"] = LogLevel.Warning, ["Error"] = LogLevel.Error, ["Information"] = LogLevel.Information
            };

            return((bool)lambdaParser.Eval(rule.Rule, varContext));
        }
Beispiel #3
0
        private void Notify(LoggingRule rule, LoggingItem loggingItem)
        {
            if (_publishers.ContainsKey(rule.Notification))
            {
                return;
            }

            var settings = new NotificationServiceSettings();

            _configuration.GetSection("Notification").Bind(settings);

            var options = Options.Create(settings);

            settings.ServiceName = rule.Notification;

            var publisherSettings = new RemoteServiceSettings();

            _configuration.GetSection("Notification:Publisher").Bind(publisherSettings);

            _publishers.TryAdd(rule.Notification,
                               RegisterPublisher(publisherSettings, options, _loggerFactory, _diagnosticSource, settings));

            _publishers[rule.Notification]?.Publish(JsonConvert.SerializeObject(loggingItem));
        }