mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 18:14:20 +01:00
Added documentation to undocumented functionality
This commit is contained in:
parent
f18b167f6f
commit
a62896cf9f
|
@ -20,7 +20,7 @@ public class SerilogAdapter : LogAdapterBase
|
||||||
private readonly global::Serilog.ILogger _serilogLogger;
|
private readonly global::Serilog.ILogger _serilogLogger;
|
||||||
private readonly MessageTemplateParser _messageTemplateParser;
|
private readonly MessageTemplateParser _messageTemplateParser;
|
||||||
|
|
||||||
public override void HandleLog(object? sender, LogCapsule? capsule)
|
public override void HandleLog(object? processor, LogCapsule? capsule)
|
||||||
{
|
{
|
||||||
if (capsule == null)
|
if (capsule == null)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ILogger interface for creating loggers that can be used by the <see cref="LogService"/>
|
||||||
|
/// </summary>
|
||||||
public interface ILogger
|
public interface ILogger
|
||||||
{
|
{
|
||||||
public void Trace(string message, params object?[]? parameters);
|
public void Trace(string message, params object?[]? parameters);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base for creating log adpaters.
|
||||||
|
/// </summary>
|
||||||
public abstract class LogAdapterBase
|
public abstract class LogAdapterBase
|
||||||
{
|
{
|
||||||
public LogAdapterBase(string adapterName)
|
public LogAdapterBase(string adapterName)
|
||||||
|
@ -10,9 +13,17 @@ public abstract class LogAdapterBase
|
||||||
|
|
||||||
internal readonly EventHandler<LogCapsule> HandleLogEvent;
|
internal readonly EventHandler<LogCapsule> HandleLogEvent;
|
||||||
public string Id { get; } = Guid.NewGuid().ToString();
|
public string Id { get; } = Guid.NewGuid().ToString();
|
||||||
|
/// <summary>
|
||||||
|
/// The name this adapter has.
|
||||||
|
/// </summary>
|
||||||
public string AdapterName { get; }
|
public string AdapterName { get; }
|
||||||
|
|
||||||
public abstract void HandleLog(object? sender, LogCapsule? capsule);
|
/// <summary>
|
||||||
|
/// Handle the incomming <see cref="LogCapsule"/> that the <see cref="LogProcessor"/> sends.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="processor">The log processor that has processed this log</param>
|
||||||
|
/// <param name="capsule">The log capsule, which contains the log information</param>
|
||||||
|
public abstract void HandleLog(object? processor, LogCapsule? capsule);
|
||||||
|
|
||||||
public override int GetHashCode() => HashCode.Combine(Id, AdapterName);
|
public override int GetHashCode() => HashCode.Combine(Id, AdapterName);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will contain all the log event information that the log adapter will receive.
|
||||||
|
/// </summary>
|
||||||
public class LogCapsule
|
public class LogCapsule
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The log serverty this log event is being logged.
|
||||||
|
/// </summary>
|
||||||
public LogSeverity Severity { get; set; }
|
public LogSeverity Severity { get; set; }
|
||||||
public string Message { get; set; } = string.Empty;
|
public string Message { get; set; } = string.Empty;
|
||||||
public Exception? Exception { get; set; }
|
public Exception? Exception { get; set; }
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Options for loggers, processor and <see cref="LogService"/>.
|
||||||
|
/// </summary>
|
||||||
public class LogOptions
|
public class LogOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Log processor, this class runs a task that send the logs (<see cref="LogCapsule"/>) to all adapters that are registered in the <see cref="LogService"/> class.
|
||||||
|
/// </summary>
|
||||||
public class LogProcessor : IDisposable
|
public class LogProcessor : IDisposable
|
||||||
{
|
{
|
||||||
public LogProcessor()
|
public LogProcessor()
|
||||||
|
@ -21,8 +24,11 @@ public class LogProcessor : IDisposable
|
||||||
private readonly ManualResetEvent _threadShutdownEvent = new ManualResetEvent(false);
|
private readonly ManualResetEvent _threadShutdownEvent = new ManualResetEvent(false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop the LogProcessor, the processor cannot be resumed after it is stopped!
|
/// Stop the LogProcessor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The processor cannot be resumed after it is stopped!
|
||||||
|
/// </remarks>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
_threadShutdownEvent.Set();
|
_threadShutdownEvent.Set();
|
||||||
|
@ -79,7 +85,7 @@ public class LogProcessor : IDisposable
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine("==================================================================================");
|
Console.WriteLine("==================================================================================");
|
||||||
Console.ForegroundColor = oldColor;
|
Console.ForegroundColor = oldColor;
|
||||||
//TODO: Write info to disk.
|
//TODO: Write to disk.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,9 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main log service class, handles the loggers, log processor and adapters.
|
||||||
|
/// </summary>
|
||||||
public static class LogService
|
public static class LogService
|
||||||
{
|
{
|
||||||
static LogService()
|
static LogService()
|
||||||
|
@ -27,6 +30,25 @@ public static class LogService
|
||||||
Adapters.Add(logAdapter);
|
Adapters.Add(logAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
/// <example>
|
||||||
|
/// <code>
|
||||||
|
/// public class Program
|
||||||
|
/// {
|
||||||
|
/// public Program
|
||||||
|
/// {
|
||||||
|
/// logger = LogService.RegisterLogger(nameof(Program));
|
||||||
|
/// }
|
||||||
|
/// private ILogger logger;
|
||||||
|
/// }
|
||||||
|
/// </code>
|
||||||
|
/// </example>
|
||||||
|
/// <remarks>At the moment this function will only return the default <see cref="Logger"/> class, this is not configureble at the moment!</remarks>
|
||||||
|
/// <param name="identifier">The identifier name of the logger, this will be passed to the log adapter as the source.</param>
|
||||||
|
/// <returns>The configured <see cref="ILogger"/> implementation that will be configuered in the <see cref="LogOptions"/> at the <see cref="LogService"/> class</returns>
|
||||||
public static ILogger RegisterLogger(string identifier)
|
public static ILogger RegisterLogger(string identifier)
|
||||||
{
|
{
|
||||||
var asm = Assembly.GetCallingAssembly();
|
var asm = Assembly.GetCallingAssembly();
|
||||||
|
@ -36,6 +58,9 @@ public static class LogService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data struct for holding calling source information.
|
||||||
|
/// </summary>
|
||||||
public struct CallingSource
|
public struct CallingSource
|
||||||
{
|
{
|
||||||
private CallingSource(Assembly asm)
|
private CallingSource(Assembly asm)
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
namespace DotBased.Logging;
|
namespace DotBased.Logging;
|
||||||
|
|
||||||
public class Logger : ILogger
|
/// <summary>
|
||||||
|
/// Main base logger, this class is the default logger that the <see cref="LogService.RegisterLogger"/> function will return.
|
||||||
|
/// </summary>
|
||||||
|
public class Logger(string identifier, CallingSource source, ref Action<LogCapsule> logProcessorHandler) : ILogger
|
||||||
{
|
{
|
||||||
public Logger(string identifier, CallingSource source, ref Action<LogCapsule> logProcessorHandler)
|
public string Identifier { get; } = identifier;
|
||||||
{
|
public CallingSource Source { get; } = source;
|
||||||
Identifier = identifier;
|
|
||||||
Source = source;
|
|
||||||
_processLog = logProcessorHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Identifier { get; }
|
private readonly Action<LogCapsule> _processLog = logProcessorHandler;
|
||||||
public CallingSource Source { get; }
|
|
||||||
|
|
||||||
private readonly Action<LogCapsule> _processLog;
|
|
||||||
|
|
||||||
public void Log(LogCapsule capsule)
|
public void Log(LogCapsule capsule)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
namespace DotBased.Utilities;
|
namespace DotBased.Utilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This class has some generator functions.
|
||||||
|
/// </summary>
|
||||||
public static class Generator
|
public static class Generator
|
||||||
{
|
{
|
||||||
private static readonly Random Random = new Random();
|
private static readonly Random Random = new Random();
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
namespace DotBased.Utilities;
|
namespace DotBased.Utilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Suffix functions for multiple types of values
|
||||||
|
/// </summary>
|
||||||
public static class Suffix
|
public static class Suffix
|
||||||
{
|
{
|
||||||
private static readonly string[] SizeSuffixes =
|
private static readonly string[] SizeSuffixes =
|
||||||
["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the bytes to the memory suffix.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bytes">The bytes to convert</param>
|
||||||
|
/// <param name="decimalPlaces">How manay decimal places will be placed</param>
|
||||||
|
/// <returns>The suffixed bytes in the correct format</returns>
|
||||||
public static string BytesToSizeSuffix(long bytes, int decimalPlaces = 1)
|
public static string BytesToSizeSuffix(long bytes, int decimalPlaces = 1)
|
||||||
{
|
{
|
||||||
if (decimalPlaces < 0)
|
if (decimalPlaces < 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user