Files
SamplePreSystem-CS/SamplePre.Common/LoggerHelper.cs
2026-04-30 11:34:41 +08:00

101 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SamplePre.Common
{
/// <summary>
/// nLog使用帮助类
/// </summary>
public class LoggerHelper
{
/// <summary>
/// 实例化nLog即为获取配置文件相关信息(获取以当前正在初始化的类命名的记录器)
/// </summary>
private readonly NLog.Logger _logger = LogManager.GetCurrentClassLogger();
private static LoggerHelper _obj;
public static LoggerHelper Logger
{
get => _obj ?? (new LoggerHelper());
set => _obj = value;
}
#region Debug
public void Debug(string msg)
{
_logger.Debug(msg);
}
public void Debug(string msg, Exception err)
{
_logger.Debug(err, msg);
}
#endregion
#region Info
public void Info(string msg)
{
_logger.Info(msg);
}
public void Info(string msg, Exception err)
{
_logger.Info(err, msg);
}
#endregion
#region Warn
public void Warn(string msg)
{
_logger.Warn(msg);
}
public void Warn(string msg, Exception err)
{
_logger.Warn(err, msg);
}
#endregion
#region Trace
public void Trace(string msg)
{
_logger.Trace(msg);
}
public void Trace(string msg, Exception err)
{
_logger.Trace(err, msg);
}
#endregion
#region Error
public void Error(string msg)
{
_logger.Error(msg);
}
public void Error(string msg, Exception err)
{
_logger.Error(err, msg);
}
#endregion
#region Fatal,
public void Fatal(string msg)
{
_logger.Fatal(msg);
}
public void Fatal(string msg, Exception err)
{
_logger.Fatal(err, msg);
}
#endregion
}
}