From a62896cf9f7087f574947b2c78e898731c2ce3a8 Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Sat, 4 May 2024 11:31:14 +0200 Subject: [PATCH] Added documentation to undocumented functionality --- DotBased.Logging.Serilog/SerilogAdapter.cs | 2 +- DotBased/Logging/ILogger.cs | 3 +++ DotBased/Logging/LogAdapterBase.cs | 13 ++++++++++- DotBased/Logging/LogCapsule.cs | 6 ++++++ DotBased/Logging/LogOptions.cs | 3 +++ DotBased/Logging/LogProcessor.cs | 12 ++++++++--- DotBased/Logging/LogService.cs | 25 ++++++++++++++++++++++ DotBased/Logging/Logger.cs | 18 ++++++---------- DotBased/Utilities/Generator.cs | 3 +++ DotBased/Utilities/Suffix.cs | 9 ++++++++ 10 files changed, 78 insertions(+), 16 deletions(-) diff --git a/DotBased.Logging.Serilog/SerilogAdapter.cs b/DotBased.Logging.Serilog/SerilogAdapter.cs index e16c6bf..88c36ec 100644 --- a/DotBased.Logging.Serilog/SerilogAdapter.cs +++ b/DotBased.Logging.Serilog/SerilogAdapter.cs @@ -20,7 +20,7 @@ public class SerilogAdapter : LogAdapterBase private readonly global::Serilog.ILogger _serilogLogger; private readonly MessageTemplateParser _messageTemplateParser; - public override void HandleLog(object? sender, LogCapsule? capsule) + public override void HandleLog(object? processor, LogCapsule? capsule) { if (capsule == null) return; diff --git a/DotBased/Logging/ILogger.cs b/DotBased/Logging/ILogger.cs index 66e2090..4adc402 100644 --- a/DotBased/Logging/ILogger.cs +++ b/DotBased/Logging/ILogger.cs @@ -1,5 +1,8 @@ namespace DotBased.Logging; +/// +/// The ILogger interface for creating loggers that can be used by the +/// public interface ILogger { public void Trace(string message, params object?[]? parameters); diff --git a/DotBased/Logging/LogAdapterBase.cs b/DotBased/Logging/LogAdapterBase.cs index ecd322f..863620c 100644 --- a/DotBased/Logging/LogAdapterBase.cs +++ b/DotBased/Logging/LogAdapterBase.cs @@ -1,5 +1,8 @@ namespace DotBased.Logging; +/// +/// The base for creating log adpaters. +/// public abstract class LogAdapterBase { public LogAdapterBase(string adapterName) @@ -10,9 +13,17 @@ public abstract class LogAdapterBase internal readonly EventHandler HandleLogEvent; public string Id { get; } = Guid.NewGuid().ToString(); + /// + /// The name this adapter has. + /// public string AdapterName { get; } - public abstract void HandleLog(object? sender, LogCapsule? capsule); + /// + /// Handle the incomming that the sends. + /// + /// The log processor that has processed this log + /// The log capsule, which contains the log information + public abstract void HandleLog(object? processor, LogCapsule? capsule); public override int GetHashCode() => HashCode.Combine(Id, AdapterName); diff --git a/DotBased/Logging/LogCapsule.cs b/DotBased/Logging/LogCapsule.cs index 5f6b0d6..b8a94f5 100644 --- a/DotBased/Logging/LogCapsule.cs +++ b/DotBased/Logging/LogCapsule.cs @@ -1,7 +1,13 @@ namespace DotBased.Logging; +/// +/// This will contain all the log event information that the log adapter will receive. +/// public class LogCapsule { + /// + /// The log serverty this log event is being logged. + /// public LogSeverity Severity { get; set; } public string Message { get; set; } = string.Empty; public Exception? Exception { get; set; } diff --git a/DotBased/Logging/LogOptions.cs b/DotBased/Logging/LogOptions.cs index f748af8..740a9c3 100644 --- a/DotBased/Logging/LogOptions.cs +++ b/DotBased/Logging/LogOptions.cs @@ -1,5 +1,8 @@ namespace DotBased.Logging; +/// +/// Options for loggers, processor and . +/// public class LogOptions { /// diff --git a/DotBased/Logging/LogProcessor.cs b/DotBased/Logging/LogProcessor.cs index 1a46755..e0ce76a 100644 --- a/DotBased/Logging/LogProcessor.cs +++ b/DotBased/Logging/LogProcessor.cs @@ -1,5 +1,8 @@ namespace DotBased.Logging; +/// +/// Log processor, this class runs a task that send the logs () to all adapters that are registered in the class. +/// public class LogProcessor : IDisposable { public LogProcessor() @@ -21,8 +24,11 @@ public class LogProcessor : IDisposable private readonly ManualResetEvent _threadShutdownEvent = new ManualResetEvent(false); /// - /// Stop the LogProcessor, the processor cannot be resumed after it is stopped! + /// Stop the LogProcessor /// + /// + /// The processor cannot be resumed after it is stopped! + /// public void Stop() { _threadShutdownEvent.Set(); @@ -42,7 +48,7 @@ public class LogProcessor : IDisposable if (!_threadSuspendEvent.WaitOne(0)) _threadSuspendEvent.Set(); } - + private void ProcessLog() { try @@ -79,7 +85,7 @@ public class LogProcessor : IDisposable Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("=================================================================================="); Console.ForegroundColor = oldColor; - //TODO: Write info to disk. + //TODO: Write to disk. } } } \ No newline at end of file diff --git a/DotBased/Logging/LogService.cs b/DotBased/Logging/LogService.cs index 4305eeb..cb8813f 100644 --- a/DotBased/Logging/LogService.cs +++ b/DotBased/Logging/LogService.cs @@ -2,6 +2,9 @@ using System.Reflection; namespace DotBased.Logging; +/// +/// Main log service class, handles the loggers, log processor and adapters. +/// public static class LogService { static LogService() @@ -27,6 +30,25 @@ public static class LogService Adapters.Add(logAdapter); } + /// + /// Register a logger that will be used in a class and will live as long as the class. + /// This will get the calling assembly and will pass that through ther log adapters. + /// + /// + /// + /// public class Program + /// { + /// public Program + /// { + /// logger = LogService.RegisterLogger(nameof(Program)); + /// } + /// private ILogger logger; + /// } + /// + /// + /// At the moment this function will only return the default class, this is not configureble at the moment! + /// The identifier name of the logger, this will be passed to the log adapter as the source. + /// The configured implementation that will be configuered in the at the class public static ILogger RegisterLogger(string identifier) { var asm = Assembly.GetCallingAssembly(); @@ -36,6 +58,9 @@ public static class LogService } } +/// +/// Data struct for holding calling source information. +/// public struct CallingSource { private CallingSource(Assembly asm) diff --git a/DotBased/Logging/Logger.cs b/DotBased/Logging/Logger.cs index f8bb6a3..8bccd56 100644 --- a/DotBased/Logging/Logger.cs +++ b/DotBased/Logging/Logger.cs @@ -1,18 +1,14 @@ namespace DotBased.Logging; -public class Logger : ILogger +/// +/// Main base logger, this class is the default logger that the function will return. +/// +public class Logger(string identifier, CallingSource source, ref Action logProcessorHandler) : ILogger { - public Logger(string identifier, CallingSource source, ref Action logProcessorHandler) - { - Identifier = identifier; - Source = source; - _processLog = logProcessorHandler; - } + public string Identifier { get; } = identifier; + public CallingSource Source { get; } = source; - public string Identifier { get; } - public CallingSource Source { get; } - - private readonly Action _processLog; + private readonly Action _processLog = logProcessorHandler; public void Log(LogCapsule capsule) { diff --git a/DotBased/Utilities/Generator.cs b/DotBased/Utilities/Generator.cs index a447773..870b71d 100644 --- a/DotBased/Utilities/Generator.cs +++ b/DotBased/Utilities/Generator.cs @@ -1,5 +1,8 @@ namespace DotBased.Utilities; +/// +/// This class has some generator functions. +/// public static class Generator { private static readonly Random Random = new Random(); diff --git a/DotBased/Utilities/Suffix.cs b/DotBased/Utilities/Suffix.cs index e353fa8..60ed314 100644 --- a/DotBased/Utilities/Suffix.cs +++ b/DotBased/Utilities/Suffix.cs @@ -1,10 +1,19 @@ namespace DotBased.Utilities; +/// +/// Suffix functions for multiple types of values +/// public static class Suffix { private static readonly string[] SizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + /// + /// Converts the bytes to the memory suffix. + /// + /// The bytes to convert + /// How manay decimal places will be placed + /// The suffixed bytes in the correct format public static string BytesToSizeSuffix(long bytes, int decimalPlaces = 1) { if (decimalPlaces < 0)