You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSV.Entity;
namespace POSV.Utils
{
public class LogUtils
{
protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static void WriteLog(LogAction action ,string logInfo, string authNo = "", string tradeNo = "" , decimal amount = 0 , string productNo = "",string skuId = "")
{
try
{
if(Global.Instance.Authc == null)
{
logger.Debug("未登录收银系统,不存储操作日志");
return;
}
var log = new Log();
log.Id = IdWorkerUtils.Instance.NextId();
log.TenantId = Global.Instance.Authc.TenantId;
log.StoreNo = Global.Instance.Authc.StoreNo;
log.PosNo = Global.Instance.Authc.PosNo;
log.WorkerNo = Global.Instance.Worker.No;
log.AuthNo = string.IsNullOrEmpty(authNo) ? log.WorkerNo : authNo;
log.Action = action.ToString();
log.Memo = logInfo;
log.TradeNo = tradeNo;
log.ProductNo = productNo;
log.SpecId = skuId;
log.Amount = amount;
log.UploadStatus = -1;
lock (Global.Instance.SyncLock)
{
using (var db = Global.Instance.OpenDataBase)
{
using(var trans = db.GetTransaction())
{
db.Save<Log>(log);
trans.Complete();
}
}
}
}
catch (Exception ex)
{
logger.Error(ex , "日志存储异常");
}
}
}
public enum LogAction
{
= 0,
= 1
}
}