From 341da63fe63e2cae3337c5a090624400d7244c11 Mon Sep 17 00:00:00 2001
From: zrg <z18737863051@163.com>
Date: 星期二, 02 七月 2024 21:22:18 +0800
Subject: [PATCH] 钉钉消息加入日志,
---
DingDingMsg/DingDingMsg/DBHelper.cs | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/DingDingMsg/DingDingMsg/DBHelper.cs b/DingDingMsg/DingDingMsg/DBHelper.cs
index 3b3b2a1..efce6a2 100644
--- a/DingDingMsg/DingDingMsg/DBHelper.cs
+++ b/DingDingMsg/DingDingMsg/DBHelper.cs
@@ -1,7 +1,9 @@
-锘縰sing System;
+锘縰sing 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;
@@ -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)
+ {
+ }
+ }
}
}
--
Gitblit v1.9.1