Admin
2025-12-02 9e42f0dafa019f5ecf6b0ff425ecb966b002171e
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.LogEnum;
 
namespace WIDESEA_Core.Utilities
{
    public class LogRecord
    {
        /// <summary>
        /// 日志记录
        /// </summary>
        /// <param name="type">1=入库 2=出库 3=盘点 4=行车</param>
        /// <param name="content"></param>
        /// <param name="stacker"></param>
        public static void WriteLog(LogEnum type ,string content, string stacker = null)
        {
            string filename = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
            if(stacker != null)
                filename = DateTime.Now.ToString("yyyy-MM-dd-") + stacker + ".txt";
 
            string month = DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月";
 
            string dir = "D:\\WCS_log\\InBound\\"+ month +"\\"+ DateTime.Now.ToString("yyyy-MM-dd")+"\\";
            if(type == LogEnum.OutBound)
                dir = "D:\\WCS_log\\OutBound\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
            else if(type == LogEnum.AGV)
                dir = "D:\\WCS_log\\AGV\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
            else if (type == LogEnum.RGV)
                dir = "D:\\WCS_log\\RGV\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
            else if(type == LogEnum.System)
                dir = "D:\\WCS_log\\System\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
 
            StackTrace trace = new StackTrace();
            StackFrame frame = trace.GetFrame(1); //1代表上级,2代表上上级,以此类推
            MethodBase method = frame.GetMethod();
            string methodName = method.Name;
            string className = method.ReflectedType.FullName;
 
            string resultstr = DateTime.Now.ToString("【yyyy-MM-dd HH:mm:ss.fff】") + "===>" +  content;
 
            if (string.IsNullOrEmpty(content))
                resultstr = "\r\n\r\n";
 
            FileHelper.WriteLog(dir, filename, resultstr + "\r\n");
        }
    }
}