1
zrg
2025-02-19 a6290d3d9de7053bc41443ce0b0e0643f4d891e6
DingDingMsg/DingDingMsg/DBHelper.cs
@@ -1,7 +1,9 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -38,15 +40,15 @@
        }
        public DBHelper()
        {
            sServer = "47.96.97.237,15127";
            sDataBase = "HX_LMESsys";
            sUser = "HX_USER";
            sPassword = "lc@841022";
            ////斯莫尔
            //sServer = "10.11.18.195";
            //sDataBase = "HX_LMESsys_test";
            //sServer = "47.96.97.237,15127";
            //sDataBase = "HX_LMESsys";
            //sUser = "HX_USER";
            //sPassword = "lc@841022";
            ////斯莫尔
            sServer = "30.10.7.6";
            sDataBase = "HX_LMESsys_test";
            sUser = "HX_USER";
            sPassword = "lc@841022";
        }
        private bool CnOpen()//OPEN数据库连接
@@ -431,5 +433,47 @@
            CnClose();
            CnDispose();
        }
        private static readonly object lockObj = new object();
        //写日志
        public static void CustomWriteLog(object obj, string FileName, string filePath = "Vlog", bool isAppend = true)
        {
            try
            {
                lock (lockObj)
                {
                    filePath = $@"{filePath}\{FileName}.txt";
                    filePath = AppDomain.CurrentDomain.BaseDirectory + filePath;
                    if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath)))
                    {
                        System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    }
                    bool fileExists = System.IO.File.Exists(filePath);
                    //不存在 则创建该文件
                    if (!fileExists)
                    {
                        System.IO.File.Create(filePath).Close();
                    }
                    using (StreamWriter writer = new StreamWriter(filePath, isAppend))
                    {
                        //存在的时候才写一行
                        if (fileExists && isAppend)
                        {
                            writer.WriteLine();
                        }
                        var content = obj is string ? obj : JsonConvert.SerializeObject(obj);
                        writer.WriteLine($"{DateTime.Now} {content}");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}