protected virtual bool MatchesFilterConditions(LoggingEvent loggingEvent, IFilter filter)
        {
            if (filter.MinLevel != LoggingEventLevel.None && loggingEvent.Level < filter.MinLevel)
                return false;

            if (filter.MaxLevel != LoggingEventLevel.None && loggingEvent.Level > filter.MaxLevel)
                return false;

            if (!filter.LogKeyContains.IsNullOrEmpty() && loggingEvent.LogKey.IndexOf(filter.LogKeyContains, StringComparison.OrdinalIgnoreCase) < 0)
                return false;

            if (!filter.LogKeyStartsWith.IsNullOrEmpty() && !loggingEvent.LogKey.StartsWith(filter.LogKeyStartsWith, StringComparison.OrdinalIgnoreCase))
                return false;

            if (!filter.TextContains.IsNullOrEmpty() && loggingEvent.Text.IndexOf(filter.TextContains, StringComparison.OrdinalIgnoreCase) < 0)
                return false;

            if (!filter.TextStartsWith.IsNullOrEmpty() && !loggingEvent.Text.StartsWith(filter.TextStartsWith, StringComparison.OrdinalIgnoreCase))
                return false;

            if (filter.MinValue.HasValue && loggingEvent.Value.HasValue && loggingEvent.Value.Value < filter.MinValue.Value)
                return false;

            if (filter.MaxValue.HasValue && loggingEvent.Value.HasValue && loggingEvent.Value.Value > filter.MaxValue.Value)
                return false;

            if (!filter.TagsContains.IsNullOrEmpty())
            {
                var requiredTags = TagHelpers.Clean(filter.TagsContains);
                if (!requiredTags.All(x => loggingEvent.Tags.Contains(x, StringComparer.OrdinalIgnoreCase)))
                    return false;
            }

            return true;
        }
Exemplo n.º 2
0
 public virtual void Push(LoggingEvent loggingEvent, bool async)
 {
     if (async)
         new PushDelegate(PushInternal).BeginInvoke(loggingEvent, null, null);
     else
         PushInternal(loggingEvent);
 }
Exemplo n.º 3
0
        public void Log(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
                throw new ArgumentNullException("loggingEvent");

            if (!_settings.Enabled)
                return;

            _repository.Save(loggingEvent);
        }
        protected virtual bool CompliesTargetConditionsAndIgnores(LoggingEvent loggingEvent, Target target)
        {
            if (loggingEvent == null)
                throw new ArgumentNullException("loggingEvent");

            if (target == null)
                throw new ArgumentNullException("target");

            if (!MatchesFilterConditions(loggingEvent, target))
                return false;

            var matchesAnyIgnoreFilter = target.Ignores != null && target.Ignores.Any(ignoreFilter => MatchesFilterConditions(loggingEvent, ignoreFilter));

            if (matchesAnyIgnoreFilter)
                return false;

            return true;
        }
Exemplo n.º 5
0
        protected void PushInternal(LoggingEvent loggingEvent)
        {
            var loggers = GetTargets().ToList();

            if (!loggers.Any())
                throw new InvalidOperationException("Cannot Push without Targets");

            foreach (var logger in loggers)
            {
                try
                {
                    logger.Log(loggingEvent);
                }
                catch (Exception)
                {
                    // TODO save logging event locally and push it
                }
            }
        }
        public virtual void Push(LoggingEvent[] loggingEvents)
        {
            var targets = GetTargets();
            foreach (var target in targets)
            {
                try
                {
                    var loggingEventsToPush = loggingEvents.Where(x => CompliesTargetConditionsAndIgnores(x, target)).ToArray();

                    if (loggingEventsToPush.Length > 0)
                        target.Push(loggingEventsToPush);
                }
                catch (Exception ex)
                {
                    if (LogManager.Configuration.ThrowExceptions)
                        throw;

                    // a target may fail but we need to continue with the others
                    PulsusDebugger.Error(target, ex);
                }
            }
        }
Exemplo n.º 7
0
        public void Log(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
                throw new ArgumentNullException("loggingEvent");

            if (!_settings.Enabled)
                return;

            var url = Url ?? _settings.Url;
            if (string.IsNullOrEmpty(url))
                throw new Exception("There is no URL defined for the remote logger.");

            Uri uri;
            if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
                throw new Exception("The URL defined for the remote logger is not valid");

            var logKey = LogKey ?? _settings.LogKey;
            if (string.IsNullOrEmpty(logKey))
                throw new Exception("There is no LogKey defined for the remote logger");

            var remoteLoggingEvent = RemoteLoggingEvent.Create(LogKey ?? _settings.LogKey, loggingEvent);

            Post(uri, remoteLoggingEvent);
        }
Exemplo n.º 8
0
 public static void Push(LoggingEvent loggingEvent)
 {
     Push(new[] { loggingEvent });
 }
Exemplo n.º 9
0
        public static void Push(LoggingEvent[] loggingEvents)
        {
            if (!Configuration.Enabled)
                return;

            _eventDispatcher.Push(loggingEvents);
        }
Exemplo n.º 10
0
 public void Log(LoggingEvent loggingEvent)
 {
 }
Exemplo n.º 11
0
 public static RemoteLoggingEvent Create(string logKey, LoggingEvent loggingEvent)
 {
     var remote = new RemoteLoggingEvent();
     remote.LogKey = logKey;
     remote.Timestamp = loggingEvent.Timestamp;
     remote.Level = loggingEvent.Level;
     remote.User = loggingEvent.User;
     remote.Source = loggingEvent.Source;
     remote.Text = loggingEvent.Text;
     remote.Value = loggingEvent.Value;
     remote.Tags = loggingEvent.Tags;
     remote.Data = loggingEvent.Data;
     return remote;
 }