AutoDispatching/AutoDispathingWork/Domains/LogInfo.cs
2024-08-12 23:45:18 +08:00

67 lines
1.9 KiB
C#

using System.Runtime.CompilerServices;
using AutoDispathingWork.Utils;
using LiteDB;
namespace WorkerService1.Domains;
public class LogInfo
{
public LogInfo()
{
}
public LogInfo(string level, string message, [CallerMemberName] string from = "")
{
Id = Guid.NewGuid();
CreateTime = DateTime.UtcNow;
Message = message;
Level = level;
From = from;
}
public Guid Id { get; set; }
public string Message { get; set; }
public string From { get; set; }
public string Level { get; set; }
public DateTime CreateTime { get; set; }
}
public static class LogInfoExtensions
{
public static LogInfo Info(this string message, [CallerMemberName] string from = "")
{
var logger = StaticServiceProvider.GetLogger(from);
logger.LogInformation(message);
var log = new LogInfo("Info", message, from);
StaticServiceProvider.AddLog(log);
return log;
}
public static LogInfo Error(this string message, [CallerMemberName] string from = "")
{
var logger = StaticServiceProvider.GetLogger(from);
logger.LogError(message);
var log = new LogInfo("Error", message, from);
StaticServiceProvider.AddLog(log);
return log;
}
public static LogInfo Warning(this string message, [CallerMemberName] string from = "")
{
var logger = StaticServiceProvider.GetLogger(from);
logger.LogWarning(message);
var log = new LogInfo("Warning", message, from);
StaticServiceProvider.AddLog(log);
return log;
}
public static LogInfo Debug(this string message, [CallerMemberName] string from = "")
{
var logger = StaticServiceProvider.GetLogger(from);
logger.LogDebug(message);
var log = new LogInfo("Debug", message, from);
StaticServiceProvider.AddLog(log);
return log;
}
}