mirror of
https://github.com/Stone-Red-Code/CuteUtils.git
synced 2026-09-04 00:46:11 +02:00
Update old xml docs
This commit is contained in:
@@ -34,11 +34,12 @@ public enum TableStyle
|
|||||||
public static class CollectionExt
|
public static class CollectionExt
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prints all items of an <see cref="IEnumerable{T}"/>
|
/// Prints the elements of the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="collection"></param>
|
/// <typeparam name="T">The type of the elements in the collection.</typeparam>
|
||||||
/// <param name="delimiter"></param>
|
/// <param name="collection">The collection to print.</param>
|
||||||
/// <param name="printToDebugConsole"></param>
|
/// <param name="delimiter">The delimiter character to use between elements. Default is ','.</param>
|
||||||
|
/// <param name="printToDebugConsole">Indicates whether to print to the debug console. Default is false.</param>
|
||||||
public static void Print<T>(this IEnumerable<T> collection, char delimiter = ',', bool printToDebugConsole = false)
|
public static void Print<T>(this IEnumerable<T> collection, char delimiter = ',', bool printToDebugConsole = false)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -63,11 +64,11 @@ public static class CollectionExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates and prints table from 2D array
|
/// Prints the elements of the 2D array in a table format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T">The type of the elements in the array.</typeparam>
|
||||||
/// <param name="array"></param>
|
/// <param name="array">The 2D array to print.</param>
|
||||||
/// <param name="tableStyle"></param>
|
/// <param name="tableStyle">The style of the table. Default is TableStyle.Default.</param>
|
||||||
public static void PrintTable<T>(this T[,] array, TableStyle tableStyle = TableStyle.Default)
|
public static void PrintTable<T>(this T[,] array, TableStyle tableStyle = TableStyle.Default)
|
||||||
{
|
{
|
||||||
int[] itemLength = new int[array.GetLength(1)];
|
int[] itemLength = new int[array.GetLength(1)];
|
||||||
@@ -126,4 +127,4 @@ public static class CollectionExt
|
|||||||
}
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ namespace CuteUtils;
|
|||||||
public static class ConsoleExt
|
public static class ConsoleExt
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the text representation of the specified object to the standard output stream.
|
/// Writes the specified value to the console with the specified color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value">The value to write.</param>
|
||||||
/// <param name="color"></param>
|
/// <param name="color">The color of the text.</param>
|
||||||
public static void Write(object value, ConsoleColor color)
|
public static void Write(object value, ConsoleColor color)
|
||||||
{
|
{
|
||||||
lock (Console.Out)
|
lock (Console.Out)
|
||||||
@@ -27,10 +27,10 @@ public static class ConsoleExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
|
/// Writes the specified value to the console with the specified color and appends a new line.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value">The value to write.</param>
|
||||||
/// <param name="color"></param>
|
/// <param name="color">The color of the text.</param>
|
||||||
public static void WriteLine(object value, ConsoleColor color)
|
public static void WriteLine(object value, ConsoleColor color)
|
||||||
{
|
{
|
||||||
lock (Console.Out)
|
lock (Console.Out)
|
||||||
@@ -45,9 +45,9 @@ public static class ConsoleExt
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
|
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T">The type to convert the input string to.</typeparam>
|
||||||
/// <returns>The input string converted to the specified type.</returns>
|
/// <returns>The input string converted to the specified type.</returns>
|
||||||
/// <exception cref="NotSupportedException"></exception>
|
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
|
||||||
public static T ReadLine<T>()
|
public static T ReadLine<T>()
|
||||||
{
|
{
|
||||||
string attemptedValue = Console.ReadLine() ?? string.Empty;
|
string attemptedValue = Console.ReadLine() ?? string.Empty;
|
||||||
@@ -60,9 +60,9 @@ public static class ConsoleExt
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
|
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T">The type to convert the input string to.</typeparam>
|
||||||
/// <param name="input">The input string converted to the specified type.</param>
|
/// <param name="input">The input string converted to the specified type.</param>
|
||||||
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/></returns>
|
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/>.</returns>
|
||||||
public static bool TryReadLine<T>([NotNullWhen(true)] out T? input)
|
public static bool TryReadLine<T>([NotNullWhen(true)] out T? input)
|
||||||
{
|
{
|
||||||
string attemptedValue = Console.ReadLine() ?? string.Empty;
|
string attemptedValue = Console.ReadLine() ?? string.Empty;
|
||||||
@@ -84,9 +84,9 @@ public static class ConsoleExt
|
|||||||
/// Obtains the next character or function key pressed by the user and converts it to the specified type.
|
/// Obtains the next character or function key pressed by the user and converts it to the specified type.
|
||||||
/// The pressed key is displayed in the console window.
|
/// The pressed key is displayed in the console window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the </typeparam>
|
/// <typeparam name="T">The type to convert the input character to.</typeparam>
|
||||||
/// <returns>The input character converted to the specified type.</returns>
|
/// <returns>The input character converted to the specified type.</returns>
|
||||||
/// <exception cref="NotSupportedException"></exception>
|
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
|
||||||
public static T ReadKey<T>()
|
public static T ReadKey<T>()
|
||||||
{
|
{
|
||||||
string attemptedValue = Console.ReadKey().KeyChar.ToString();
|
string attemptedValue = Console.ReadKey().KeyChar.ToString();
|
||||||
@@ -101,15 +101,14 @@ public static class ConsoleExt
|
|||||||
/// The pressed key is displayed in the console window.
|
/// The pressed key is displayed in the console window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">The input character converted to the specified type.</param>
|
/// <param name="input">The input character converted to the specified type.</param>
|
||||||
/// <typeparam name="T">The type of the </typeparam>
|
/// <typeparam name="T">The type to convert the input character to.</typeparam>
|
||||||
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/></returns>
|
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/>.</returns>
|
||||||
public static bool TryReadKey<T>([NotNullWhen(true)] out T? input)
|
public static bool TryReadKey<T>([NotNullWhen(true)] out T? input)
|
||||||
{
|
{
|
||||||
string attemptedValue = Console.ReadKey().KeyChar.ToString();
|
string attemptedValue = Console.ReadKey().KeyChar.ToString();
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
TypeConverter converter = TypeDescriptor.GetConverter(type);
|
TypeConverter converter = TypeDescriptor.GetConverter(type);
|
||||||
if (converter != null && converter.IsValid(attemptedValue))
|
if (converter != null && converter.IsValid(attemptedValue))
|
||||||
|
|
||||||
{
|
{
|
||||||
input = (T)converter.ConvertFromString(attemptedValue)!;
|
input = (T)converter.ConvertFromString(attemptedValue)!;
|
||||||
return true;
|
return true;
|
||||||
@@ -122,10 +121,10 @@ public static class ConsoleExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Suspends execution of the current method until the user presses a key
|
/// Suspends execution of the current method until the user presses a key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key that has to be pressed</param>
|
/// <param name="key">The key that has to be pressed.</param>
|
||||||
/// <param name="message">The message that will be displayed</param>
|
/// <param name="message">The message that will be displayed.</param>
|
||||||
public static void Pause(ConsoleKey key, string? message = null)
|
public static void Pause(ConsoleKey key, string? message = null)
|
||||||
{
|
{
|
||||||
Console.WriteLine(message ?? $"Press {key} to continue...");
|
Console.WriteLine(message ?? $"Press {key} to continue...");
|
||||||
@@ -137,12 +136,12 @@ public static class ConsoleExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Suspends execution of the current method until the user presses a key
|
/// Suspends execution of the current method until the user presses a key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message that will be displayed</param>
|
/// <param name="message">The message that will be displayed.</param>
|
||||||
public static void Pause(string message = "Press any key to continue...")
|
public static void Pause(string message = "Press any key to continue...")
|
||||||
{
|
{
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
_ = Console.ReadKey(true);
|
_ = Console.ReadKey(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,35 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Title>CuteUtils</Title>
|
<Title>CuteUtils</Title>
|
||||||
<Authors>Stone_Red</Authors>
|
<Authors>Stone_Red</Authors>
|
||||||
<PackageProjectUrl>https://github.com/Stone-Red-Code/CuteUtils</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Stone-Red-Code/CuteUtils</PackageProjectUrl>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<PropertyGroup>
|
||||||
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
|
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
|
||||||
<PackageReference Include="Vsxmd" Version="1.4.5">
|
<Deterministic>False</Deterministic>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
</PropertyGroup>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<None Include="..\..\README.md">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Vsxmd" Version="1.4.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -9,172 +9,172 @@ namespace CuteUtils.Logging;
|
|||||||
public class Logger
|
public class Logger
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The logging configuration.
|
/// Gets or sets the log configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogConfig Config { get; init; } = new LogConfig();
|
public LogConfig Config { get; init; } = new LogConfig();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a message with the specified source, log severity, and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="logSeverity"></param>
|
/// <param name="logSeverity">The severity level of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void Log(string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void Log(string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a message with the specified log severity and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="logSeverity"></param>
|
/// <param name="logSeverity">The severity level of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void Log(string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void Log(string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs an informational message with the specified source and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogInfo(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogInfo(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs an informational message with additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogInfo(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogInfo(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a warning message with the specified source and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogWarn(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogWarn(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a warning message with additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogWarn(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogWarn(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs an error message with additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogError(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogError(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs an error message with the specified source and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogError(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogError(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a fatal error message with additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogFatal(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogFatal(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a fatal error message with the specified source and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogFatal(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogFatal(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a debug message with additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogDebug(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogDebug(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, string.Empty, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, string.Empty, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output
|
/// Logs a debug message with the specified source and additional caller information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogDebug(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogDebug(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
WriteLog(message, source, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber);
|
WriteLog(message, source, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output if the condition is met
|
/// Logs a message with the specified source, log severity, and additional caller information if the condition is met.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="condition"></param>
|
/// <param name="condition">The condition to check.</param>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source">The source of the log message.</param>
|
||||||
/// <param name="logSeverity"></param>
|
/// <param name="logSeverity">The severity level of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogIf(bool condition, string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogIf(bool condition, string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
if (condition)
|
if (condition)
|
||||||
@@ -184,14 +184,14 @@ public class Logger
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Log the message to the specified output if the condition is met
|
/// Logs a message with the specified log severity and additional caller information if the condition is met.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="condition"></param>
|
/// <param name="condition">The condition to check.</param>
|
||||||
/// <param name="message"></param>
|
/// <param name="message">The message to log.</param>
|
||||||
/// <param name="logSeverity"></param>
|
/// <param name="logSeverity">The severity level of the log message.</param>
|
||||||
/// <param name="memberName"></param>
|
/// <param name="memberName">The name of the calling member.</param>
|
||||||
/// <param name="sourceFilePath"></param>
|
/// <param name="sourceFilePath">The path of the source file.</param>
|
||||||
/// <param name="sourceLineNumber"></param>
|
/// <param name="sourceLineNumber">The line number in the source file.</param>
|
||||||
public void LogIf(bool condition, string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
public void LogIf(bool condition, string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||||
{
|
{
|
||||||
if (condition)
|
if (condition)
|
||||||
@@ -201,8 +201,9 @@ public class Logger
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears the log file
|
/// Clears the log file for the specified log severity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="logSeverity">The severity level of the log messages to clear.</param>
|
||||||
public void ClearLogFile(LogSeverity logSeverity)
|
public void ClearLogFile(LogSeverity logSeverity)
|
||||||
{
|
{
|
||||||
OutputConfig outputConfig = GetOutputConfig(logSeverity);
|
OutputConfig outputConfig = GetOutputConfig(logSeverity);
|
||||||
@@ -257,7 +258,7 @@ public class Logger
|
|||||||
File.Create(outputConfig.FilePath).Close();
|
File.Create(outputConfig.FilePath).Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
File.AppendAllLines(outputConfig.FilePath, [fileOutput]);
|
File.AppendAllLines(outputConfig.FilePath, new[] { fileOutput });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,4 +274,4 @@ public class Logger
|
|||||||
_ => Config.DebugConfig
|
_ => Config.DebugConfig
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,13 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RandomExt
|
public static class RandomExt
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a random item from the specified enumerable.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the items in the enumerable.</typeparam>
|
||||||
|
/// <param name="random">The random number generator.</param>
|
||||||
|
/// <param name="enumerable">The enumerable to select a random item from.</param>
|
||||||
|
/// <returns>A random item from the enumerable.</returns>
|
||||||
public static T NextItem<T>(this Random random, IEnumerable<T> enumerable)
|
public static T NextItem<T>(this Random random, IEnumerable<T> enumerable)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(enumerable);
|
ArgumentNullException.ThrowIfNull(enumerable);
|
||||||
@@ -12,19 +19,37 @@ public static class RandomExt
|
|||||||
return enumerable.ElementAt(random.Next(enumerable.Count()));
|
return enumerable.ElementAt(random.Next(enumerable.Count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a random boolean value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="random">The random number generator.</param>
|
||||||
|
/// <returns>A random boolean value.</returns>
|
||||||
public static bool NextBool(this Random random)
|
public static bool NextBool(this Random random)
|
||||||
{
|
{
|
||||||
return random.Next(2) == 0;
|
return random.Next(2) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a random value from the specified enum type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The enum type.</typeparam>
|
||||||
|
/// <param name="random">The random number generator.</param>
|
||||||
|
/// <returns>A random value from the enum type.</returns>
|
||||||
public static T NextEnum<T>(this Random random) where T : struct, Enum
|
public static T NextEnum<T>(this Random random) where T : struct, Enum
|
||||||
{
|
{
|
||||||
T[] values = Enum.GetValues<T>();
|
T[] values = Enum.GetValues<T>();
|
||||||
return values[random.Next(values.Length)];
|
return values[random.Next(values.Length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a random value from the specified array of enum values.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The enum type.</typeparam>
|
||||||
|
/// <param name="random">The random number generator.</param>
|
||||||
|
/// <param name="values">The array of enum values.</param>
|
||||||
|
/// <returns>A random value from the array of enum values.</returns>
|
||||||
public static T NextEnum<T>(this Random random, T[] values) where T : struct, Enum
|
public static T NextEnum<T>(this Random random, T[] values) where T : struct, Enum
|
||||||
{
|
{
|
||||||
return values[random.Next(values.Length)];
|
return values[random.Next(values.Length)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user