adding messages rate limit, form, controller

This commit is contained in:
2026-10-27 15:31:45 +02:00
parent 35aed79337
commit c5c9d74937
15 changed files with 306 additions and 36 deletions
+28
View File
@@ -0,0 +1,28 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Console;
namespace StatiKosev.Logging;
public sealed class Logger() : ConsoleFormatter("color")
{
public override void Write<TState>(in LogEntry<TState> entry,
IExternalScopeProvider? scopeProvider, TextWriter writer)
{
var message = entry.Formatter(entry.State, entry.Exception);
if (message is null) return;
var color = entry.LogLevel switch
{
LogLevel.Information => "\e[32m", // green
LogLevel.Warning => "\e[33m", // yellow
LogLevel.Error or LogLevel.Critical => "\e[31m", // red
LogLevel.Debug or LogLevel.Trace => "\e[90m", // gray
_ => ""
};
var reset = color.Length > 0 ? "\e[0m" : "";
writer.WriteLine($"{color}{DateTime.Now:HH:mm:ss} {entry.LogLevel,-11} {entry.Category}: {message}{reset}");
if (entry.Exception is not null)
writer.WriteLine($"{color}{entry.Exception}{reset}");
}
}