mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 10:04:20 +01:00
Moving some functionality from ToolQit lib
This commit is contained in:
parent
1785433a67
commit
8c75917f6f
|
@ -9,7 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotBased.Log.Serilog\DotBased.Log.Serilog.csproj" />
|
||||
<ProjectReference Include="..\DotBased.Logging.Serilog\DotBased.Logging.Serilog.csproj" />
|
||||
<ProjectReference Include="..\DotBased\DotBased.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -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
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Utilities\" />
|
||||
<Folder Include="Collections\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
6
DotBased/Extensions/StringExtensions.cs
Normal file
6
DotBased/Extensions/StringExtensions.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsNullOrWhiteSpace(this string s) => string.IsNullOrWhiteSpace(s);
|
||||
}
|
8
DotBased/Utilities/Generator.cs
Normal file
8
DotBased/Utilities/Generator.cs
Normal 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}";
|
||||
}
|
31
DotBased/Utilities/Suffix.cs
Normal file
31
DotBased/Utilities/Suffix.cs
Normal 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]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user