using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Threading.Tasks; using Hh.Mes.Common.Http; using Hh.Mes.POJO.Entity; namespace Hh.Mes.Service.Logs { /// <summary> /// 接口日志队列 /// </summary> public class QueueJobLog { private static QueueJobLog _Log; private static ConcurrentQueue<sys_job_log> queue; private static readonly object LockHelper = new object(); private QueueJobLog() { } public static QueueJobLog GetInstance { get { if (_Log == null) { lock (LockHelper) { if (_Log == null) { _Log = new QueueJobLog(); queue = new ConcurrentQueue<sys_job_log>(); } } } return _Log; } } public ConcurrentQueue<sys_job_log> Queue() { return queue; } public string getFileName() { StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(5);//1代表上级,2代表上上级,以此类推 MethodBase method = frame.GetMethod(); string className = method.ReflectedType?.Name; return className + method; } /// <summary> /// 接口队列 接收,发送写日志 /// </summary> public void EnqueueJobLog( string jobName, string methodName, string methodParams, string user , string jobMessage,string jobGroup) { var sysLog = new sys_job_log { jobName = jobName, methodName = methodName, methodParams = methodParams, jobMessage = jobMessage, jobGroup= jobGroup, exceptionInfo = getFileName(), createTime = DateTime.Now, createBy = user }; queue.Enqueue(sysLog); } } }