|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace AUCMA.STORE.Common
|
|
|
{
|
|
|
public class LogHelper
|
|
|
{
|
|
|
//GetLogger表示log4net配置文件中logger标签中name属性,此处要一致 不然无log输出
|
|
|
public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
|
|
|
public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
|
|
|
public static readonly log4net.ILog heartbeat = log4net.LogManager.GetLogger("heartbeat");
|
|
|
public static readonly log4net.ILog recordInfo = log4net.LogManager.GetLogger("recordInfo");
|
|
|
public static readonly log4net.ILog pilerlog = log4net.LogManager.GetLogger("pilerlog");
|
|
|
public static readonly log4net.ILog leftPilerlog = log4net.LogManager.GetLogger("leftPilerlog");
|
|
|
public static readonly log4net.ILog rightPilerlog = log4net.LogManager.GetLogger("rightPilerlog");
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录Info日志
|
|
|
/// </summary>
|
|
|
/// <param name="msg"></param>
|
|
|
/// <param name="ex"></param>
|
|
|
public static void Info(string msg)
|
|
|
{
|
|
|
if (loginfo.IsInfoEnabled)
|
|
|
{
|
|
|
loginfo.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 出入库记录日志
|
|
|
/// </summary>
|
|
|
/// <param name="msg"></param>
|
|
|
public static void record(string msg)
|
|
|
{
|
|
|
if (loginfo.IsInfoEnabled)
|
|
|
{
|
|
|
recordInfo.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录心跳日志
|
|
|
/// </summary>
|
|
|
/// <param name="msg"></param>
|
|
|
public static void HeartBeat(string msg)
|
|
|
{
|
|
|
if (heartbeat.IsInfoEnabled)
|
|
|
{
|
|
|
heartbeat.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void Pilerlog(string msg)
|
|
|
{
|
|
|
if (pilerlog.IsInfoEnabled)
|
|
|
{
|
|
|
pilerlog.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void LeftPilerlog(string msg)
|
|
|
{
|
|
|
if (leftPilerlog.IsInfoEnabled)
|
|
|
{
|
|
|
leftPilerlog.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void RightPilerlog(string msg)
|
|
|
{
|
|
|
if (rightPilerlog.IsInfoEnabled)
|
|
|
{
|
|
|
rightPilerlog.Info(msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录Error日志
|
|
|
/// </summary>
|
|
|
/// <param name="errorMsg"></param>
|
|
|
/// <param name="ex"></param>
|
|
|
public static void Error(string info, Exception ex = null)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(info) && ex == null)
|
|
|
{
|
|
|
logerror.ErrorFormat("【附加信息】 : {0}<br>", new object[] { info });
|
|
|
}
|
|
|
else if (!string.IsNullOrEmpty(info) && ex != null)
|
|
|
{
|
|
|
string errorMsg = BeautyErrorMsg(ex);
|
|
|
logerror.ErrorFormat("【附加信息】 : {0}<br>{1}", new object[] { info, errorMsg });
|
|
|
}
|
|
|
else if (string.IsNullOrEmpty(info) && ex != null)
|
|
|
{
|
|
|
string errorMsg = BeautyErrorMsg(ex);
|
|
|
logerror.Error(errorMsg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 美化错误信息
|
|
|
/// </summary>
|
|
|
/// <param name="ex">异常</param>
|
|
|
/// <returns>错误信息</returns>
|
|
|
private static string BeautyErrorMsg(Exception ex)
|
|
|
{
|
|
|
string errorMsg = string.Format("【异常类型】:{0} <br>【异常信息】:{1} <br>【堆栈调用】:{2}", new object[] { ex.GetType().Name, ex.Message, ex.StackTrace });
|
|
|
errorMsg = errorMsg.Replace("\r\n", "<br>");
|
|
|
errorMsg = errorMsg.Replace("位置", "<strong style=\"color:red\">位置</strong>");
|
|
|
return errorMsg;
|
|
|
}
|
|
|
}
|
|
|
}
|