Example #1
0
 public override void Clear()
 {
     if (!_AllowClear)
     {
         throw new InvalidOperationException();
     }
     foreach (Logger master in _Masters.ToArray())
     {
         try {
             master.Clear();
         } catch (Exception ex) { CallOnError(ex); }
     }
 }
Example #2
0
        // ============ Implementations ============

        // Internal method to convert an entry to string. Return null if any filter says no or input/result is null.
        protected virtual string EntryToString(LogEntry entry, LogFilter[] filters = null)
        {
            if (entry == null)
            {
                return(null);
            }
            if (filters == null)
            {
                filters = _Filters.ToArray();
            }
            foreach (LogFilter filter in filters)
            {
                try {
                    if (!filter(entry))
                    {
                        return(null);
                    }
                } catch (Exception ex) { CallOnError(ex); }
            }

            var txt = entry.Message?.ToString();

            if (string.IsNullOrEmpty(txt))
            {
                return(null);
            }

            if (entry.Args?.Length > 0 && txt != null)
            {
                try {
                    return(string.Format(txt, entry.Args));
                } catch (FormatException ex) { CallOnError(ex); }
            }
            return(txt);
        }