// Copyright (C) 2018, The Duplicati Team // http://www.duplicati.com, info@duplicati.com // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA using System; namespace Duplicati.Library.Logging { /// /// A log destinations that invokes a method /// internal class FunctionLogDestination : ILogDestination { /// /// The method to call for logging /// private readonly Action m_entry; /// /// Initializes a new instance of the class. /// /// The method to call for logging. public FunctionLogDestination(Action entry) { m_entry = entry ?? throw new ArgumentNullException(nameof(entry)); } /// /// Writes the message by invoking the handler. /// /// The entry to log. public void WriteMessage(LogEntry entry) { m_entry.Invoke(entry); } } /// /// A log filter that wraps a callback method /// internal class FunctionFilter : ILogFilter { /// /// The method to call for filtering /// private readonly Func m_handler; /// /// Initializes a new instance of the class. /// /// The method to call for filtering. public FunctionFilter(Func handler) { m_handler = handler ?? throw new ArgumentNullException(nameof(handler)); } /// /// Determines if the element is accepted or nor /// /// A value indicating if the value is accepted or not. /// The log entry to filter. public bool Accepts(LogEntry entry) { return m_handler(entry); } } }