Moving some functionality from ToolQit lib

This commit is contained in:
Max 2024-04-24 16:52:25 +02:00
parent 1785433a67
commit 8c75917f6f
9 changed files with 57 additions and 7 deletions

View File

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DotBased.Log.Serilog\DotBased.Log.Serilog.csproj" /> <ProjectReference Include="..\DotBased.Logging.Serilog\DotBased.Logging.Serilog.csproj" />
<ProjectReference Include="..\DotBased\DotBased.csproj" /> <ProjectReference Include="..\DotBased\DotBased.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,6 +1,6 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using DotBased.Log.Serilog; using DotBased.Logging.Serilog;
using DotBased.Logging; using DotBased.Logging;
using Serilog; using Serilog;
using ILogger = Serilog.ILogger; 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!"); logger.Fatal(new NullReferenceException("Test exception"),"Test FATAL log!");
Console.ReadKey(); Console.ReadKey();
return;
ILogger SetupSerilog() ILogger SetupSerilog()
{ {
LoggerConfiguration logConfig = new LoggerConfiguration() var logConfig = new LoggerConfiguration()
.MinimumLevel.Verbose() .MinimumLevel.Verbose()
.WriteTo.Console(outputTemplate: SerilogAdapter.SampleTemplate); .WriteTo.Console(outputTemplate: SerilogAdapter.SampleTemplate);
return logConfig.CreateLogger(); return logConfig.CreateLogger();

View File

@ -2,11 +2,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using DotBased.Logging;
using Serilog.Events; using Serilog.Events;
using Serilog.Parsing; using Serilog.Parsing;
namespace DotBased.Log.Serilog; namespace DotBased.Logging.Serilog;
public class SerilogAdapter : LogAdapterBase public class SerilogAdapter : LogAdapterBase
{ {

View File

@ -4,7 +4,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased", "DotBased\DotBas
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLI", "CLI\CLI.csproj", "{BAC347B8-42D9-42E1-999A-8CDBE73E9A49}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLI", "CLI\CLI.csproj", "{BAC347B8-42D9-42E1-999A-8CDBE73E9A49}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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.ActiveCfg = Release|Any CPU
{EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}.Release|Any CPU.Build.0 = Release|Any CPU {EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC} = {2156FB93-C252-4B33-8A0C-73C82FABB163}
EndGlobalSection
EndGlobal EndGlobal

View File

@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Utilities\" /> <Folder Include="Collections\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,6 @@
namespace DotBased.Extensions;
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(this string s) => string.IsNullOrWhiteSpace(s);
}

View File

@ -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}";
}

View File

@ -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]);
}
}