mirror of
https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities.git
synced 2026-09-04 00:56:24 +02:00
Added namespaces in separate files and added logging class
This commit is contained in:
Binary file not shown.
Binary file not shown.
-147
@@ -157,151 +157,4 @@ namespace Stone_Red_Utilities.ArrListExtentions
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Stone_Red_Utilities.BoolExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="bool"/> Extentions
|
||||
/// </summary>
|
||||
public static class BoolExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets value to true if input is true. If input is false the value will not change.
|
||||
/// </summary>
|
||||
/// <param name="bol"></param>
|
||||
/// <param name="input"></param>
|
||||
public static void OneWayTrue(this ref bool bol, bool input)
|
||||
{
|
||||
if (bol == false && input)
|
||||
bol = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets value to false if input is false. If input is true the value will not change.
|
||||
/// </summary>
|
||||
/// <param name="bol"></param>
|
||||
/// <param name="input"></param>
|
||||
public static void OneWayFalse(this ref bool bol, bool input)
|
||||
{
|
||||
if (bol == true && !input)
|
||||
bol = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Stone_Red_Utilities.ColorConsole
|
||||
{
|
||||
/// <summary>
|
||||
/// Console Extentions
|
||||
/// </summary>
|
||||
public static class ConsoleExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of the specified object to the standard output stream.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="color"></param>
|
||||
public static void Write(object value, ConsoleColor color)
|
||||
{
|
||||
lock (Console.Out)
|
||||
{
|
||||
ConsoleColor oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = color;
|
||||
Console.Write(value);
|
||||
Console.ForegroundColor = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="color"></param>
|
||||
public static void WriteLine(object value, ConsoleColor color)
|
||||
{
|
||||
lock (Console.Out)
|
||||
{
|
||||
ConsoleColor oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = color;
|
||||
Console.WriteLine(value);
|
||||
Console.ForegroundColor = oldColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Stone_Red_Utilities.StringExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="string"/> Extentions
|
||||
/// </summary>
|
||||
public static class StringExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of upper and lower case.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreCase(this string str, string value)
|
||||
{
|
||||
return str.ToLower().Equals(value.ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of spaces.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreSpaces(this string str, string value)
|
||||
{
|
||||
return str.Replace(" ", string.Empty).Equals(value.Replace(" ", string.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of upper and lower case and spaces.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreSpacesAndCase(this string str, string value)
|
||||
{
|
||||
return str.Replace(" ", string.Empty).ToLower().Equals(value.Replace(" ", string.Empty).ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all invalid chars from file name
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="allowSpaces"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToFileName(this string str, bool allowSpaces = false)
|
||||
{
|
||||
char[] invalidChars = Path.GetInvalidFileNameChars();
|
||||
|
||||
if (!allowSpaces)
|
||||
str = str.Replace(" ", string.Empty);
|
||||
|
||||
foreach (var item in invalidChars)
|
||||
{
|
||||
str = str.Replace(item.ToString(), string.Empty);
|
||||
}
|
||||
|
||||
var normalizedString = str.Normalize(NormalizationForm.FormD);
|
||||
var stringBuilder = new StringBuilder();
|
||||
|
||||
foreach (var c in normalizedString)
|
||||
{
|
||||
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
||||
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
||||
{
|
||||
stringBuilder.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Stone_Red_Utilities.BoolExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="bool"/> Extentions
|
||||
/// </summary>
|
||||
public static class BoolExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets value to true if input is true. If input is false the value will not change.
|
||||
/// </summary>
|
||||
/// <param name="bol"></param>
|
||||
/// <param name="input"></param>
|
||||
public static void OneWayTrue(this ref bool bol, bool input)
|
||||
{
|
||||
if (bol == false && input)
|
||||
bol = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets value to false if input is false. If input is true the value will not change.
|
||||
/// </summary>
|
||||
/// <param name="bol"></param>
|
||||
/// <param name="input"></param>
|
||||
public static void OneWayFalse(this ref bool bol, bool input)
|
||||
{
|
||||
if (bol == true && !input)
|
||||
bol = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
|
||||
namespace Stone_Red_Utilities.ConsoleExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// Console Extentions
|
||||
/// </summary>
|
||||
public static class ConsoleExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of the specified object to the standard output stream.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="color"></param>
|
||||
public static void Write(object value, ConsoleColor color)
|
||||
{
|
||||
lock (Console.Out)
|
||||
{
|
||||
ConsoleColor oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = color;
|
||||
Console.Write(value);
|
||||
Console.ForegroundColor = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="color"></param>
|
||||
public static void WriteLine(object value, ConsoleColor color)
|
||||
{
|
||||
lock (Console.Out)
|
||||
{
|
||||
ConsoleColor oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = color;
|
||||
Console.WriteLine(value);
|
||||
Console.ForegroundColor = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends execution until the user presses a key
|
||||
/// </summary>
|
||||
/// <param name="enterKeyOnly"></param>
|
||||
/// <param name="customMessage"></param>
|
||||
public static void Pause(bool enterKeyOnly = false, string customMessage = null)
|
||||
{
|
||||
if (customMessage is null)
|
||||
{
|
||||
if (enterKeyOnly)
|
||||
{
|
||||
Console.WriteLine("Press ENTER to continue.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Press any key to continue.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(customMessage);
|
||||
}
|
||||
|
||||
if (enterKeyOnly)
|
||||
{
|
||||
Console.ReadLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
|
||||
namespace Stone_Red_Utilities.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the severity of the log target.
|
||||
/// </summary>
|
||||
public enum LogTarget
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes log to console
|
||||
/// </summary>
|
||||
Console,
|
||||
|
||||
/// <summary>
|
||||
/// Writes log to debug console
|
||||
/// </summary>
|
||||
DebugConsole,
|
||||
|
||||
/// <summary>
|
||||
/// Writes log to file
|
||||
/// </summary>
|
||||
File,
|
||||
|
||||
/// <summary>
|
||||
/// Writes log to console and file
|
||||
/// </summary>
|
||||
ConsoleAndFile,
|
||||
|
||||
/// <summary>
|
||||
/// Writes log to debug console and file
|
||||
/// </summary>
|
||||
DebugAndFile,
|
||||
|
||||
/// <summary>
|
||||
/// Writes log to console debug console and file
|
||||
/// </summary>
|
||||
All
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the severity of the log message.
|
||||
/// </summary>
|
||||
public enum LogSeverity
|
||||
{
|
||||
/// <summary>
|
||||
/// Logs that contain the most detailed messages.
|
||||
/// </summary>
|
||||
Debug,
|
||||
|
||||
/// <summary>
|
||||
/// Logs that track the general flow of the application.
|
||||
/// </summary>
|
||||
Info,
|
||||
|
||||
/// <summary>
|
||||
/// Logs that highlight an abnormal activity in the flow of execution.
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Logs that highlight when the flow of execution is stopped due to a failure.
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// Logs that contain the most severe level of error. This type of error indicate that immediate attention may be required.
|
||||
/// </summary>
|
||||
Fatal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class used for logging
|
||||
/// </summary>
|
||||
public class Logger
|
||||
{
|
||||
private readonly string logPath;
|
||||
private readonly LogTarget logTarget;
|
||||
|
||||
/// <summary>
|
||||
/// Format that is used when logging to the console
|
||||
/// </summary>
|
||||
public string ConsoleLogFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Format that is used when logging to the debug console
|
||||
/// </summary>
|
||||
public string DebugConsoleLogFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Format that is used when logging to a file
|
||||
/// </summary>
|
||||
public string FileLogFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the logger with the default format
|
||||
/// </summary>
|
||||
/// <param name="defaultFormat"></param>
|
||||
/// <param name="logTarg"></param>
|
||||
/// <param name="file"></param>
|
||||
public Logger(LogTarget logTarg = LogTarget.Console, string file = null, string defaultFormat = "{<dateTime>:HH:mm:ss} | {<level>,-7} | {<source>,-15} | {<message>}")
|
||||
{
|
||||
if (logTarg == LogTarget.ConsoleAndFile || logTarg == LogTarget.DebugAndFile || logTarg == LogTarget.File || logTarg == LogTarget.All)
|
||||
logPath = file ?? throw new ArgumentNullException($"file can't be null!");
|
||||
|
||||
logTarget = logTarg;
|
||||
ConsoleLogFormat = defaultFormat;
|
||||
DebugConsoleLogFormat = defaultFormat;
|
||||
FileLogFormat = defaultFormat;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the logger with the default format
|
||||
/// </summary>
|
||||
/// <param name="defaultFormat"></param>
|
||||
/// <param name="logTarg"></param>
|
||||
public Logger(LogTarget logTarg = LogTarget.Console, string defaultFormat = "{<dateTime:HH:mm:ss>} | {<level>,-7} | {<source>,-15} | {<message>}")
|
||||
{
|
||||
if (logTarg == LogTarget.ConsoleAndFile || logTarg == LogTarget.DebugAndFile || logTarg == LogTarget.File || logTarg == LogTarget.All)
|
||||
throw new ArgumentNullException($"file can't be null!");
|
||||
|
||||
logTarget = logTarg;
|
||||
ConsoleLogFormat = defaultFormat;
|
||||
DebugConsoleLogFormat = defaultFormat;
|
||||
FileLogFormat = defaultFormat;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log the message to the specified output
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="logSeverity"></param>
|
||||
/// <param name="memberName"></param>
|
||||
/// <param name="sourceFilePath"></param>
|
||||
/// <param name="sourceLineNumber"></param>
|
||||
public void Log(string message, string source, LogSeverity logSeverity = LogSeverity.Info, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
WriteLog(message, source, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log the message to the specified output when the condition is met
|
||||
/// </summary>
|
||||
/// <param name="condition"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="logSeverity"></param>
|
||||
/// <param name="memberName"></param>
|
||||
/// <param name="sourceFilePath"></param>
|
||||
/// <param name="sourceLineNumber"></param>
|
||||
public void LogIf(bool condition, string message, string source, LogSeverity logSeverity = LogSeverity.Info, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
if (condition)
|
||||
WriteLog(message, source, logSeverity, memberName, sourceFilePath, sourceLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears log file
|
||||
/// </summary>
|
||||
public void ClearLogFile()
|
||||
{
|
||||
if (File.Exists(logPath))
|
||||
File.WriteAllText(logPath, string.Empty);
|
||||
}
|
||||
|
||||
private void WriteLog(string message, string source, LogSeverity logSeverity, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
|
||||
{
|
||||
string consoleOutput = GetFormattedString(ConsoleLogFormat, logSeverity, source, message, memberName, sourceFilePath, sourceLineNumber);
|
||||
string debugOutput = GetFormattedString(DebugConsoleLogFormat, logSeverity, source, message, memberName, sourceFilePath, sourceLineNumber);
|
||||
string fileOutput = GetFormattedString(FileLogFormat, logSeverity, source, message, memberName, sourceFilePath, sourceLineNumber);
|
||||
|
||||
switch (logTarget)
|
||||
{
|
||||
case LogTarget.Console:
|
||||
ConsoleExt.WriteLine(consoleOutput, GetColor(logSeverity));
|
||||
break;
|
||||
|
||||
case LogTarget.DebugConsole:
|
||||
Debug.WriteLine(debugOutput);
|
||||
break;
|
||||
|
||||
case LogTarget.File:
|
||||
File.AppendAllLines(logPath, new[] { fileOutput });
|
||||
break;
|
||||
|
||||
case LogTarget.ConsoleAndFile:
|
||||
ConsoleExt.WriteLine(consoleOutput, GetColor(logSeverity));
|
||||
File.AppendAllLines(logPath, new[] { fileOutput });
|
||||
break;
|
||||
|
||||
case LogTarget.DebugAndFile:
|
||||
Debug.WriteLine(debugOutput);
|
||||
File.AppendAllLines(logPath, new[] { fileOutput });
|
||||
break;
|
||||
|
||||
case LogTarget.All:
|
||||
Debug.WriteLine(debugOutput);
|
||||
ConsoleExt.WriteLine(consoleOutput, GetColor(logSeverity));
|
||||
File.AppendAllLines(logPath, new[] { fileOutput });
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException("Log target type not valid!");
|
||||
}
|
||||
}
|
||||
|
||||
private ConsoleColor GetColor(LogSeverity logSeverity)
|
||||
{
|
||||
return logSeverity switch
|
||||
{
|
||||
LogSeverity.Fatal => ConsoleColor.DarkRed,
|
||||
LogSeverity.Error => ConsoleColor.Red,
|
||||
LogSeverity.Warning => ConsoleColor.DarkYellow,
|
||||
LogSeverity.Info => ConsoleColor.White,
|
||||
_ => ConsoleColor.DarkGray,
|
||||
};
|
||||
}
|
||||
|
||||
private string GetFormattedString(string format, LogSeverity logSeverity, string source, string message, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
|
||||
{
|
||||
format = format
|
||||
.Replace("<dateTime>", "0")
|
||||
.Replace("<level>", "1")
|
||||
.Replace("<lineNumber>", "2")
|
||||
.Replace("<filePath>", "3")
|
||||
.Replace("<memberName>", "4")
|
||||
.Replace("<source>", "5")
|
||||
.Replace("<message>", "6");
|
||||
|
||||
return string.Format(format, DateTime.Now, logSeverity, sourceLineNumber, sourceFilePath, memberName, source, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,25 +77,153 @@
|
||||
<param name="bol"></param>
|
||||
<param name="input"></param>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.ColorConsole.ConsoleExt">
|
||||
<member name="T:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt">
|
||||
<summary>
|
||||
Console Extentions
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.ColorConsole.ConsoleExt.Write(System.Object,System.ConsoleColor)">
|
||||
<member name="M:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt.Write(System.Object,System.ConsoleColor)">
|
||||
<summary>
|
||||
Writes the text representation of the specified object to the standard output stream.
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<param name="color"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.ColorConsole.ConsoleExt.WriteLine(System.Object,System.ConsoleColor)">
|
||||
<member name="M:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt.WriteLine(System.Object,System.ConsoleColor)">
|
||||
<summary>
|
||||
Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<param name="color"></param>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.LogTarget">
|
||||
<summary>
|
||||
Specifies the severity of the log target.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.Console">
|
||||
<summary>
|
||||
Writes log to console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.DebugConsole">
|
||||
<summary>
|
||||
Writes log to debug console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.File">
|
||||
<summary>
|
||||
Writes log to file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.ConsoleAndFile">
|
||||
<summary>
|
||||
Writes log to console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.DebugAndFile">
|
||||
<summary>
|
||||
Writes log to debug console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.All">
|
||||
<summary>
|
||||
Writes log to console debug console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.LogSeverity">
|
||||
<summary>
|
||||
Specifies the severity of the log message.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Debug">
|
||||
<summary>
|
||||
Logs that contain the most detailed messages.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Info">
|
||||
<summary>
|
||||
Logs that track the general flow of the application.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Warning">
|
||||
<summary>
|
||||
Logs that highlight an abnormal activity in the flow of execution.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Error">
|
||||
<summary>
|
||||
Logs that highlight when the flow of execution is stopped due to a failure.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Fatal">
|
||||
<summary>
|
||||
Logs that contain the most severe level of error. This type of error indicate that immediate attention may be required.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.Logger">
|
||||
<summary>
|
||||
Class used for logging
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.ConsoleLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to the console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.DebugConsoleLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to the debug console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.FileLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to a file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.#ctor(Stone_Red_Utilities.Logging.LogTarget,System.String,System.String)">
|
||||
<summary>
|
||||
Initializes the logger with the default format
|
||||
</summary>
|
||||
<param name="defaultFormat"></param>
|
||||
<param name="logTarg"></param>
|
||||
<param name="file"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.#ctor(Stone_Red_Utilities.Logging.LogTarget,System.String)">
|
||||
<summary>
|
||||
Initializes the logger with the default format
|
||||
</summary>
|
||||
<param name="defaultFormat"></param>
|
||||
<param name="logTarg"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.Log(System.String,System.String,Stone_Red_Utilities.Logging.LogSeverity,System.String,System.String,System.Int32)">
|
||||
<summary>
|
||||
Log the message to the specified output
|
||||
</summary>
|
||||
<param name="message"></param>
|
||||
<param name="source"></param>
|
||||
<param name="logSeverity"></param>
|
||||
<param name="memberName"></param>
|
||||
<param name="sourceFilePath"></param>
|
||||
<param name="sourceLineNumber"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.LogIf(System.Boolean,System.String,System.String,Stone_Red_Utilities.Logging.LogSeverity,System.String,System.String,System.Int32)">
|
||||
<summary>
|
||||
Log the message to the specified output when the condition is met
|
||||
</summary>
|
||||
<param name="condition"></param>
|
||||
<param name="message"></param>
|
||||
<param name="source"></param>
|
||||
<param name="logSeverity"></param>
|
||||
<param name="memberName"></param>
|
||||
<param name="sourceFilePath"></param>
|
||||
<param name="sourceLineNumber"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.ClearLogFile">
|
||||
<summary>
|
||||
Clears log file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.StringExtentions.StringExt">
|
||||
<summary>
|
||||
<see cref="T:System.String"/> Extentions
|
||||
@@ -133,5 +261,22 @@
|
||||
<param name="allowSpaces"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.Truncate(System.String,System.Int32)">
|
||||
<summary>
|
||||
Truncates a string to the specified length.
|
||||
</summary>
|
||||
<param name="str"></param>
|
||||
<param name="length"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.Truncate(System.String,System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
Truncates a string to the specified length.
|
||||
</summary>
|
||||
<param name="str"></param>
|
||||
<param name="length"></param>
|
||||
<param name="ellipsis"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Stone_Red_Utilities.StringExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="string"/> Extentions
|
||||
/// </summary>
|
||||
public static class StringExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of upper and lower case.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreCase(this string str, string value)
|
||||
{
|
||||
return str.ToLower().Equals(value.ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of spaces.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreSpaces(this string str, string value)
|
||||
{
|
||||
return str.Replace(" ", string.Empty).Equals(value.Replace(" ", string.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance and another specified <see cref="String"/> object have the same value regardless of upper and lower case and spaces.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EqualsIgnoreSpacesAndCase(this string str, string value)
|
||||
{
|
||||
return str.Replace(" ", string.Empty).ToLower().Equals(value.Replace(" ", string.Empty).ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all invalid chars from file name
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="allowSpaces"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToFileName(this string str, bool allowSpaces = false)
|
||||
{
|
||||
char[] invalidChars = Path.GetInvalidFileNameChars();
|
||||
|
||||
if (!allowSpaces)
|
||||
str = str.Replace(" ", string.Empty);
|
||||
|
||||
foreach (var item in invalidChars)
|
||||
{
|
||||
str = str.Replace(item.ToString(), string.Empty);
|
||||
}
|
||||
|
||||
var normalizedString = str.Normalize(NormalizationForm.FormD);
|
||||
var stringBuilder = new StringBuilder();
|
||||
|
||||
foreach (var c in normalizedString)
|
||||
{
|
||||
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
||||
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
||||
{
|
||||
stringBuilder.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncates a string to the specified length.
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <returns></returns>
|
||||
public static string Truncate(this string str, int length)
|
||||
{
|
||||
if (str.Length > length && length > 0)
|
||||
return str.Substring(0, length);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncates a string to the specified length.
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="ellipsis"></param>
|
||||
/// <returns></returns>
|
||||
public static string Truncate(this string str, int length, bool ellipsis)
|
||||
{
|
||||
if (str.Length > length && length > 0)
|
||||
if (ellipsis)
|
||||
{
|
||||
return $"{str.Substring(0, length - 3)}...";
|
||||
}
|
||||
else
|
||||
{
|
||||
return str.Substring(0, length);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+148
-3
@@ -77,25 +77,153 @@
|
||||
<param name="bol"></param>
|
||||
<param name="input"></param>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.ColorConsole.ConsoleExt">
|
||||
<member name="T:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt">
|
||||
<summary>
|
||||
Console Extentions
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.ColorConsole.ConsoleExt.Write(System.Object,System.ConsoleColor)">
|
||||
<member name="M:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt.Write(System.Object,System.ConsoleColor)">
|
||||
<summary>
|
||||
Writes the text representation of the specified object to the standard output stream.
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<param name="color"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.ColorConsole.ConsoleExt.WriteLine(System.Object,System.ConsoleColor)">
|
||||
<member name="M:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt.WriteLine(System.Object,System.ConsoleColor)">
|
||||
<summary>
|
||||
Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<param name="color"></param>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.LogTarget">
|
||||
<summary>
|
||||
Specifies the severity of the log target.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.Console">
|
||||
<summary>
|
||||
Writes log to console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.DebugConsole">
|
||||
<summary>
|
||||
Writes log to debug console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.File">
|
||||
<summary>
|
||||
Writes log to file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.ConsoleAndFile">
|
||||
<summary>
|
||||
Writes log to console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.DebugAndFile">
|
||||
<summary>
|
||||
Writes log to debug console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogTarget.All">
|
||||
<summary>
|
||||
Writes log to console debug console and file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.LogSeverity">
|
||||
<summary>
|
||||
Specifies the severity of the log message.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Debug">
|
||||
<summary>
|
||||
Logs that contain the most detailed messages.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Info">
|
||||
<summary>
|
||||
Logs that track the general flow of the application.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Warning">
|
||||
<summary>
|
||||
Logs that highlight an abnormal activity in the flow of execution.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Error">
|
||||
<summary>
|
||||
Logs that highlight when the flow of execution is stopped due to a failure.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Stone_Red_Utilities.Logging.LogSeverity.Fatal">
|
||||
<summary>
|
||||
Logs that contain the most severe level of error. This type of error indicate that immediate attention may be required.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.Logging.Logger">
|
||||
<summary>
|
||||
Class used for logging
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.ConsoleLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to the console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.DebugConsoleLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to the debug console
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Stone_Red_Utilities.Logging.Logger.FileLogFormat">
|
||||
<summary>
|
||||
Format that is used when logging to a file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.#ctor(Stone_Red_Utilities.Logging.LogTarget,System.String,System.String)">
|
||||
<summary>
|
||||
Initializes the logger with the default format
|
||||
</summary>
|
||||
<param name="defaultFormat"></param>
|
||||
<param name="logTarg"></param>
|
||||
<param name="file"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.#ctor(Stone_Red_Utilities.Logging.LogTarget,System.String)">
|
||||
<summary>
|
||||
Initializes the logger with the default format
|
||||
</summary>
|
||||
<param name="defaultFormat"></param>
|
||||
<param name="logTarg"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.Log(System.String,System.String,Stone_Red_Utilities.Logging.LogSeverity,System.String,System.String,System.Int32)">
|
||||
<summary>
|
||||
Log the message to the specified output
|
||||
</summary>
|
||||
<param name="message"></param>
|
||||
<param name="source"></param>
|
||||
<param name="logSeverity"></param>
|
||||
<param name="memberName"></param>
|
||||
<param name="sourceFilePath"></param>
|
||||
<param name="sourceLineNumber"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.LogIf(System.Boolean,System.String,System.String,Stone_Red_Utilities.Logging.LogSeverity,System.String,System.String,System.Int32)">
|
||||
<summary>
|
||||
Log the message to the specified output when the condition is met
|
||||
</summary>
|
||||
<param name="condition"></param>
|
||||
<param name="message"></param>
|
||||
<param name="source"></param>
|
||||
<param name="logSeverity"></param>
|
||||
<param name="memberName"></param>
|
||||
<param name="sourceFilePath"></param>
|
||||
<param name="sourceLineNumber"></param>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.Logging.Logger.ClearLogFile">
|
||||
<summary>
|
||||
Clears log file
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Stone_Red_Utilities.StringExtentions.StringExt">
|
||||
<summary>
|
||||
<see cref="T:System.String"/> Extentions
|
||||
@@ -133,5 +261,22 @@
|
||||
<param name="allowSpaces"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.Truncate(System.String,System.Int32)">
|
||||
<summary>
|
||||
Truncates a string to the specified length.
|
||||
</summary>
|
||||
<param name="str"></param>
|
||||
<param name="length"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.Truncate(System.String,System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
Truncates a string to the specified length.
|
||||
</summary>
|
||||
<param name="str"></param>
|
||||
<param name="length"></param>
|
||||
<param name="ellipsis"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
720090d901031d5b30d715855746daa6aaddc3bc
|
||||
5da8ee29e757543d794f5481de018812db6a323f
|
||||
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.deps.json
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.dll
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.pdb
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.csprojAssemblyReference.cache
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.AssemblyInfoInputs.cache
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.AssemblyInfo.cs
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.csproj.CoreCompileInputs.cache
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.dll
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.pdb
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.xml
|
||||
C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\obj\Debug\netstandard2.1\Stone_Red-C-Sharp-Utilities.csprojAssemblyReference.cache
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -58,7 +58,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.103\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.104\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.103\\RuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.104\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "2VJSRKb/gc57sxTJshaKHZlH4eHV1dHn5znnRPKDBMMcq2gLxMBxabpH2Q44hNjbAyPx6mu//H+srU7j3iCF3Q==",
|
||||
"dgSpecHash": "aWSVR7De4Q2VY3O6G2D1iAjpBH8farjDoaC5cvp5irFy5kocS3MdyJjSHdKZ0zSh3PnZ9Aj3Gdvrb1If7qdwSg==",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
|
||||
Reference in New Issue
Block a user