From 5588fc5697a6c639f7b5c11e1865de9bc5481546 Mon Sep 17 00:00:00 2001
From: chenhaozhe <gaozhechen26@gmail.com>
Date: 星期日, 26 十月 2025 21:47:22 +0800
Subject: [PATCH] 添加 来料检验单 生产入库检验单 出厂检验单 根据物料带出检验方案 接口
---
WebAPI/LogService.cs | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/WebAPI/LogService.cs b/WebAPI/LogService.cs
index 9168f4d..113cc0d 100644
--- a/WebAPI/LogService.cs
+++ b/WebAPI/LogService.cs
@@ -11,7 +11,23 @@
public class LogService
{
private static readonly object lockObj = new object();
-
+
+ public static void WriteAsync(object obj, string filePath = "Vlog", bool isAppend = true)
+ {
+ Task.Run(() =>
+ {
+ Write(obj, filePath, isAppend);
+ });
+ }
+
+ public static void WriteAsync<T>(object obj, string filePath = "Vlog", bool isAppend = true)
+ {
+ Task.Run(() =>
+ {
+ Write(obj, $@"{filePath}\{typeof(T).Name}", isAppend);
+ });
+ }
+
#region 鏃ュ織
public static void Write(object obj, string filePath = "Vlog", bool isAppend = true)
{
@@ -53,5 +69,47 @@
}
}
#endregion
+
+ #region 鑷畾涔夋枃浠跺悕
+ 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)
+ {
+ }
+ }
+ #endregion
}
}
--
Gitblit v1.9.1