1
Huangxiaoqiang-03
2024-11-01 6e9f630e4e12738d98241b684e6227e02010b6c5
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_Core/LogHelper/Logger.cs
@@ -1,5 +1,6 @@

using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -65,6 +66,40 @@
        {
        }
        public static void Write_Log(string groupName, string logName, string content, object data = null)
        {
            DateTime nowTime = DateTime.Now;
            string basePath = System.Environment.CurrentDirectory + "/Log/" + $"/{groupName}/{nowTime.ToString("yyyy-MM-dd")}";
            //如果日志文件目录不存在,则创建
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }
            try
            {
                FileStream fs = new FileStream(basePath + "/" + logName + $"{nowTime.ToString("yyMMdd")}.txt", FileMode.Append);
                StreamWriter strwriter = new StreamWriter(fs);
                try
                {
                    strwriter.WriteLine(nowTime.ToString() + "." + nowTime.Millisecond);
                    strwriter.WriteLine(content);
                    if (data != null)
                    {
                        strwriter.WriteLine(JsonConvert.SerializeObject(data));
                    }
                    strwriter.WriteLine("-------------------------------");
                    strwriter.WriteLine();
                    strwriter.Flush();
                }
                catch { }
                finally
                {
                    strwriter.Close();
                    fs.Close();
                }
            }
            catch { }
        }
        public static void WriteApiLog2DB(HttpContext context, string requestParameter, DateTime beginDate, string responseParameter, DateTime endDate, LoggerStatus loggerStatus)
        {