diff --git a/CLI/CLI.csproj b/CLI/CLI.csproj index c4a1ef8..a104c78 100644 --- a/CLI/CLI.csproj +++ b/CLI/CLI.csproj @@ -9,7 +9,7 @@ - + diff --git a/CLI/Program.cs b/CLI/Program.cs index 5df0d6d..201c4d3 100644 --- a/CLI/Program.cs +++ b/CLI/Program.cs @@ -1,6 +1,6 @@ // See https://aka.ms/new-console-template for more information -using DotBased.Log.Serilog; +using DotBased.Logging.Serilog; using DotBased.Logging; using Serilog; using ILogger = Serilog.ILogger; @@ -19,11 +19,12 @@ logger.Error(new NullReferenceException("Test exception"),"Test ERROR log!"); logger.Fatal(new NullReferenceException("Test exception"),"Test FATAL log!"); Console.ReadKey(); +return; ILogger SetupSerilog() { - LoggerConfiguration logConfig = new LoggerConfiguration() + var logConfig = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console(outputTemplate: SerilogAdapter.SampleTemplate); return logConfig.CreateLogger(); diff --git a/DotBased.Log.Serilog/DotBased.Log.Serilog.csproj b/DotBased.Logging.Serilog/DotBased.Logging.Serilog.csproj similarity index 100% rename from DotBased.Log.Serilog/DotBased.Log.Serilog.csproj rename to DotBased.Logging.Serilog/DotBased.Logging.Serilog.csproj diff --git a/DotBased.Log.Serilog/SerilogAdapter.cs b/DotBased.Logging.Serilog/SerilogAdapter.cs similarity index 98% rename from DotBased.Log.Serilog/SerilogAdapter.cs rename to DotBased.Logging.Serilog/SerilogAdapter.cs index 33abcef..c1355d3 100644 --- a/DotBased.Log.Serilog/SerilogAdapter.cs +++ b/DotBased.Logging.Serilog/SerilogAdapter.cs @@ -2,11 +2,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using DotBased.Logging; using Serilog.Events; using Serilog.Parsing; -namespace DotBased.Log.Serilog; +namespace DotBased.Logging.Serilog; public class SerilogAdapter : LogAdapterBase { diff --git a/DotBased.sln b/DotBased.sln index d4a2a8b..9e1a483 100644 --- a/DotBased.sln +++ b/DotBased.sln @@ -4,7 +4,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased", "DotBased\DotBas EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLI", "CLI\CLI.csproj", "{BAC347B8-42D9-42E1-999A-8CDBE73E9A49}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.Log.Serilog", "DotBased.Log.Serilog\DotBased.Log.Serilog.csproj", "{EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.Logging.Serilog", "DotBased.Logging.Serilog\DotBased.Logging.Serilog.csproj", "{EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{2156FB93-C252-4B33-8A0C-73C82FABB163}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,4 +27,7 @@ Global {EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC} = {2156FB93-C252-4B33-8A0C-73C82FABB163} + EndGlobalSection EndGlobal diff --git a/DotBased/DotBased.csproj b/DotBased/DotBased.csproj index 0206358..070c822 100644 --- a/DotBased/DotBased.csproj +++ b/DotBased/DotBased.csproj @@ -8,7 +8,7 @@ - + diff --git a/DotBased/Extensions/StringExtensions.cs b/DotBased/Extensions/StringExtensions.cs new file mode 100644 index 0000000..c79638b --- /dev/null +++ b/DotBased/Extensions/StringExtensions.cs @@ -0,0 +1,6 @@ +namespace DotBased.Extensions; + +public static class StringExtensions +{ + public static bool IsNullOrWhiteSpace(this string s) => string.IsNullOrWhiteSpace(s); +} \ No newline at end of file diff --git a/DotBased/Utilities/Generator.cs b/DotBased/Utilities/Generator.cs new file mode 100644 index 0000000..a447773 --- /dev/null +++ b/DotBased/Utilities/Generator.cs @@ -0,0 +1,8 @@ +namespace DotBased.Utilities; + +public static class Generator +{ + private static readonly Random Random = new Random(); + + public static string GenerateRandomHexColor() => $"#{Random.Next(0x1000000):X6}"; +} \ No newline at end of file diff --git a/DotBased/Utilities/Suffix.cs b/DotBased/Utilities/Suffix.cs new file mode 100644 index 0000000..e353fa8 --- /dev/null +++ b/DotBased/Utilities/Suffix.cs @@ -0,0 +1,31 @@ +namespace DotBased.Utilities; + +public static class Suffix +{ + private static readonly string[] SizeSuffixes = + ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + + public static string BytesToSizeSuffix(long bytes, int decimalPlaces = 1) + { + if (decimalPlaces < 0) + decimalPlaces = 1; + switch (bytes) + { + case < 0: + return "-" + BytesToSizeSuffix(-bytes, decimalPlaces); + case 0: + return string.Format("{0:n" + decimalPlaces + "} bytes", 0); + } + + int mag = (int)Math.Log(bytes, 1024); + + decimal adjustedSize = (decimal)bytes / (1L << (mag * 10)); + + if (Math.Round(adjustedSize, decimalPlaces) >= 1000) + { + mag += 1; + adjustedSize /= 1024; + } + return string.Format("{0:n" + decimalPlaces + "} {1}", adjustedSize, SizeSuffixes[mag]); + } +} \ No newline at end of file