Files
juipnet/Infrastructure/Hncore.Infrastructure/Common/LogHelper.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2024-04-10 13:55:27 +08:00
using System;
using NLog;
namespace Hncore.Infrastructure.Common
{
public class LogHelper
{
private static readonly Logger Log = LogManager.GetLogger("UserLog");
private static string assName = AppDomain.CurrentDomain.FriendlyName;
private static string FormatMsg(string title, object msg)
{
return "Assembly" + assName + "\r\nTitle : " + title + "\r\nMessage : " + msg + "\r\n";
}
public static void Error(string title, object msg = null)
{
Log?.Error(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
public static void Debug(string title, object msg = null)
{
Log?.Debug(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
public static void Info(string title, object msg = null)
{
Log?.Info(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
public static void Warn(string title, object msg = null)
{
Log?.Warn(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
public static void Trace(string title, object msg = null)
{
Log?.Trace(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
public static void Fatal(string title, object msg = null)
{
Log?.Fatal(FormatMsg(title, msg));
Console.WriteLine(DateTime.Now+"\r\n"+FormatMsg(title, msg));
}
}
}