Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/.idea/.idea.UnmanagedString/.idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion src/.idea/.idea.UnmanagedString/.idea/.name

This file was deleted.

4 changes: 0 additions & 4 deletions src/.idea/.idea.UnmanagedString/.idea/encodings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions src/.idea/.idea.UnmanagedString/.idea/indexLayout.xml

This file was deleted.

6 changes: 0 additions & 6 deletions src/.idea/.idea.UnmanagedString/.idea/vcs.xml

This file was deleted.

410 changes: 218 additions & 192 deletions src/UnmanagedString/EntryPoint.cs

Large diffs are not rendered by default.

121 changes: 46 additions & 75 deletions src/UnmanagedString/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,47 @@
using System.Drawing;
using Colorful;
using Console = Colorful.Console;

namespace UnmanagedString;

public static class Logger
{
private const string MessageStyle = "[{0}] [{1}] {2}";

public static void Information(ReadOnlySpan<char> message)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.LightGreen),
new Formatter("INFO", Color.LightGreen),
new Formatter(message.ToString(), Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Success(ReadOnlySpan<char> message)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.Green),
new Formatter("SUCCESS", Color.Green),
new Formatter(message.ToString(), Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Warning(ReadOnlySpan<char> message)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.Yellow),
new Formatter("WARNING", Color.Yellow),
new Formatter(message.ToString(), Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Error(ReadOnlySpan<char> message)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.Red),
new Formatter("ERROR", Color.Red),
new Formatter(message.ToString(), Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Skipped(ReadOnlySpan<char> message)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.DarkGray),
new Formatter("SKIPPED", Color.DarkGray),
new Formatter(message.ToString(), Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Exception(Exception ex)
{
var replacements = new[]
{
new(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color.Red),
new Formatter("EXCEPTION", Color.Red),
new Formatter(ex.Message, Color.White)
};
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}
using Colorful;
using System.Drawing;
using Console = Colorful.Console;

namespace UnmanagedString
{
public static class Logger
{
private const string MessageStyle = "[{0}] [{1}] {2}"; // The format for log messages

private static void Log(ReadOnlySpan<char> message, string level, Color levelColor)
{
if (message == null)
{
throw new ArgumentNullException(nameof(message)); // Ensure the message is not null
}

var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // Get current timestamp
// Explicitly define the type of the array (because C# loves strong typing!)
var replacements = new Formatter[]
{
new Formatter(timestamp, Color.Gray), // Timestamp in gray
new Formatter($" {level}", levelColor), // Log level in specified color
new Formatter(message.ToString(), Color.White) // Actual message in white
};

// Log the message with formatting (like magic, but with colors!)
Console.WriteLineFormatted(MessageStyle, Color.Gray, replacements);
}

public static void Information(ReadOnlySpan<char> message) => Log(message, "INFO", Color.LightGreen); // Informational message
public static void Success(ReadOnlySpan<char> message) => Log(message, "SUCCESS", Color.Green); // Success message (yay!)
public static void Warning(ReadOnlySpan<char> message) => Log(message, "WARNING", Color.Yellow); // Warning message (uh-oh!)
public static void Error(ReadOnlySpan<char> message) => Log(message, "ERROR", Color.Red); // Error message (time to panic!)
public static void Skipped(ReadOnlySpan<char> message) => Log(message, "SKIPPED", Color.DarkGray); // Skipped message (because we can!)

public static void Exception(Exception ex)
{
if (ex == null)
{
throw new ArgumentNullException(nameof(ex)); // Ensure the exception is not null
}

Log(ex.Message.AsSpan(), "EXCEPTION", Color.Red); // Log the exception message
}
}
}
9 changes: 5 additions & 4 deletions src/UnmanagedString/UnmanagedString.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsmResolver" Version="4.11.2" />
<PackageReference Include="AsmResolver.DotNet" Version="4.11.2" />
<PackageReference Include="AsmResolver.PE" Version="4.11.2" />
<PackageReference Include="AsmResolver" Version="5.5.1" />
<PackageReference Include="AsmResolver.DotNet" Version="5.5.1" />
<PackageReference Include="AsmResolver.PE" Version="5.5.1" />
<PackageReference Include="AsmResolver.PE.File" Version="5.5.1" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
</ItemGroup>

Expand Down