Blame view

sys/Hh.Mes.Service/WebService/Logs/QueueJobLog.cs 2.18 KB
赖素文 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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);
        }
    }
}