Files
Sharpbin/PasteBin/Logging.cs
T
whoswhip bdcc3a1dc6 Refactor for async operations and add new features
Updated Compression.cs to support asynchronous operations, including new methods for decompressing byte arrays and checking compression status.
Enhanced Logging.cs with asynchronous logging methods.
Refactored Program.cs to replace synchronous calls with asynchronous ones, added a new endpoint for editing pastes, and implemented rate limiting.
Removed outdated logging configuration.
2024-10-19 00:05:59 -04:00

53 lines
2.0 KiB
C#

using Org.BouncyCastle.Asn1.Cms;
namespace Sharpbin
{
public class Logging
{
public static async Task<Log> LogRequestAsync(HttpContext context)
{
Log log = new Log();
log.Now = DateTime.Now;
log.Method = context.Request.Method;
log.Path = context.Request.Path;
log.UserAgent = context.Request.Headers["User-Agent"];
log.Referer = context.Request.Headers["Referer"];
log.IP = context.Request.Headers["X-Forwarded-For"].ToString() ?? context.Connection.RemoteIpAddress.ToString();
return log;
}
public static async Task LogError(string message)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[ERROR - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[ERROR - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
public static async Task LogInfo(string message)
{
Console.WriteLine($"[INFO - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[INFO - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
public static async Task LogWarning(string message)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($"[WARNING - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[WARNING - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
}
public class Log
{
public DateTime Now { get; set; }
public string Method { get; set; }
public string Path { get; set; }
public string UserAgent { get; set; }
public string Referer { get; set; }
public string Body { get; set; }
public string IP { get; set; }
}
}