Example #1
0
        internal Logger([NotNull] SoftString name, [NotNull] LogPredicate logPredicate, Action dispose)
        {
            _name         = name ?? throw new ArgumentNullException(nameof(name));
            _logPredicate = logPredicate;
            _dispose      = dispose;

            _observers = new HashSet <IObserver <ILog> >();
        }
Example #2
0
        public static LogPredicate LogRegex([NotNull] this LogPredicate logPredicate, Func <Log, string> getValue, [RegexPattern] string pattern, RegexOptions regexOptions = RegexOptions.None)
        {
            if (logPredicate == null)
            {
                throw new ArgumentNullException(nameof(logPredicate));
            }

            return(log => logPredicate(log) && Regex.IsMatch(getValue(log), pattern, regexOptions));
        }
Example #3
0
        public static LogPredicate ContainsException([NotNull] this LogPredicate logPredicate)
        {
            if (logPredicate == null)
            {
                throw new ArgumentNullException(nameof(logPredicate));
            }

            return(log => logPredicate(log) && log.Exception().IsNotNull());
        }
Example #4
0
        public static LogPredicate ScopeRegex([NotNull] this LogPredicate logPredicate, [RegexPattern] string pattern, RegexOptions regexOptions = RegexOptions.IgnoreCase)
        {
            if (logPredicate == null)
            {
                throw new ArgumentNullException(nameof(logPredicate));
            }

            return(log => logPredicate(log) && log.Scopes().Select(scope => scope.ToString()).Any(scope => Regex.IsMatch(scope, pattern, regexOptions)));
        }
Example #5
0
        public static LogPredicate Contains([NotNull] this LogPredicate logPredicate, [NotNull] LogLevel logLevel)
        {
            if (logLevel == null)
            {
                throw new ArgumentNullException(nameof(logLevel));
            }

            return(log => logPredicate(log) && logLevel.Contains(log.LogLevel()));
        }
Example #6
0
        public static LogPredicate Min([NotNull] this LogPredicate logPredicate, TimeSpan elapsed)
        {
            if (logPredicate == null)
            {
                throw new ArgumentNullException(nameof(logPredicate));
            }

            return(log => logPredicate(log) && elapsed <= log.Elapsed());
        }
Example #7
0
 public static LogPredicate NameRegex([NotNull] this LogPredicate logPredicate, [RegexPattern] string pattern, RegexOptions regexOptions = RegexOptions.IgnoreCase)
 {
     return(log => logPredicate(log) && logPredicate.LogRegex(l => l.Name()?.ToString() ?? string.Empty, pattern, regexOptions)(log));
 }
Example #8
0
 public static LogPredicate MessageMatches([NotNull] this LogPredicate logPredicate, [RegexPattern] string pattern, RegexOptions regexOptions = RegexOptions.IgnoreCase)
 {
     return(log => logPredicate(log) && logPredicate.ValueMatches(l => l.Message() ?? string.Empty, pattern, regexOptions)(log));
 }