2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:23 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-18 22:04:03 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2025-08-17 06:11:22 +01:00
|
|
|
// Filename : AaruLogging.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-18 22:04:03 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Console.
|
2015-10-18 22:04:03 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Handlers for normal, verbose and debug consoles.
|
2015-10-18 22:04:03 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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
|
2015-10-18 22:04:03 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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.
|
2015-10-18 22:04:03 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-18 22:04:03 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2015-10-18 22:04:03 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2023-10-08 04:10:04 +01:00
|
|
|
using System;
|
2023-10-05 01:05:20 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
2025-08-17 05:50:25 +01:00
|
|
|
namespace Aaru.Logging;
|
2022-03-06 13:29:37 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implements a console abstraction that defines four level of messages that can be routed to different consoles:
|
|
|
|
|
/// standard, error, verbose and debug.
|
|
|
|
|
/// </summary>
|
2023-10-05 01:05:20 +01:00
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
2025-08-17 06:11:22 +01:00
|
|
|
public static class AaruLogging
|
2015-10-18 22:04:03 +01:00
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Event to receive writings to the standard output console that should be followed by a line termination.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event WriteLineDelegate WriteLineEvent;
|
2023-10-03 22:51:28 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Event to receive writings to the error output console that should be followed by a line termination.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event ErrorDelegate ErrorEvent;
|
2023-10-03 22:51:28 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Event to receive writings to the verbose output console that should be followed by a line termination.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event VerboseDelegate VerboseEvent;
|
2023-10-03 22:51:28 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Event to receive line terminations to the debug output console.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event DebugDelegate DebugEvent;
|
2023-10-03 22:51:28 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Event to receive writings to the standard output console.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event WriteDelegate WriteEvent;
|
2023-10-03 22:51:28 +01:00
|
|
|
|
2023-10-08 04:10:04 +01:00
|
|
|
/// <summary>Event to receive exceptions to write to the debug output console.</summary>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static event ExceptionDelegate WriteExceptionEvent;
|
2023-10-08 04:10:04 +01:00
|
|
|
|
2025-08-17 06:59:43 +01:00
|
|
|
/// <summary>Event to receive writings to the informational output console that should be followed by a line termination.</summary>
|
|
|
|
|
public static event InformationDelegate InformationEvent;
|
|
|
|
|
|
|
|
|
|
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <summary>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
|
|
|
|
|
/// the standard output console using the specified format information.
|
2021-08-17 13:56:04 +01:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="format">A composite format string.</param>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
2022-03-06 13:29:37 +00:00
|
|
|
public static void WriteLine(string format, params object[] arg) => WriteLineEvent?.Invoke(format, arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <summary>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
|
|
|
|
|
/// the error output console using the specified format information.
|
2021-08-17 13:56:04 +01:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="format">A composite format string.</param>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static void Error(string format, params object[] arg) => ErrorEvent?.Invoke(format, arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <summary>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
|
|
|
|
|
/// the verbose output console using the specified format information.
|
2021-08-17 13:56:04 +01:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="format">A composite format string.</param>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
2025-08-17 06:02:59 +01:00
|
|
|
public static void Verbose(string format, params object[] arg) => VerboseEvent?.Invoke(format, arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2025-08-17 06:59:43 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
|
|
|
|
|
/// the verbose output console using the specified format information.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="format">A composite format string.</param>
|
|
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
|
|
|
|
public static void Information(string format, params object[] arg) => InformationEvent?.Invoke(format, arg);
|
|
|
|
|
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <summary>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
|
|
|
|
|
/// the debug output console using the specified format information.
|
2021-08-17 13:56:04 +01:00
|
|
|
/// </summary>
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <param name="module">Description of the module writing to the debug console</param>
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <param name="format">A composite format string.</param>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
2025-08-17 06:19:32 +01:00
|
|
|
public static void Debug(string module, string format, params object[] arg) =>
|
|
|
|
|
DebugEvent?.Invoke(module, format, arg);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Writes the current line terminator to the standard output console.</summary>
|
|
|
|
|
public static void WriteLine() => WriteLineEvent?.Invoke("", null);
|
|
|
|
|
|
2021-08-17 13:56:04 +01:00
|
|
|
/// <summary>
|
2022-03-06 13:29:37 +00:00
|
|
|
/// Writes the text representation of the specified array of objects to the standard output console using the
|
2021-08-17 21:23:23 +01:00
|
|
|
/// specified format information.
|
2021-08-17 13:56:04 +01:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="format">A composite format string.</param>
|
2021-08-17 21:23:23 +01:00
|
|
|
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
|
2022-03-06 13:29:37 +00:00
|
|
|
public static void Write(string format, params object[] arg) => WriteEvent?.Invoke(format, arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2023-10-08 04:10:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Writes the exception to the debug output console.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ex">Exception.</param>
|
2025-11-24 20:12:10 +00:00
|
|
|
public static void Exception(Exception ex, string message, params object[] arg) =>
|
|
|
|
|
WriteExceptionEvent?.Invoke(ex, message, arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|