mirror of
https://github.com/hmaxnl/DotBased.git
synced 2024-11-09 23:04:20 +01:00
Moving some functionality from ToolQit lib
This commit is contained in:
parent
1785433a67
commit
8c75917f6f
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
|
@ -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
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Utilities\" />
|
<Folder Include="Collections\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</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