adding messages rate limit, form, controller
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user