From 8b001c1f73d776f6b1c881c58fd1e9c6f47c4d87 Mon Sep 17 00:00:00 2001 From: 王 垚 <1402714037@qq.com> Date: 星期五, 08 七月 2022 09:56:42 +0800 Subject: [PATCH] nothing --- DAL/采购管理/ClsCg_POInStockBill.cs | 1 DAL/LogService.cs | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletions(-) diff --git a/DAL/LogService.cs b/DAL/LogService.cs new file mode 100644 index 0000000..17b75cc --- /dev/null +++ b/DAL/LogService.cs @@ -0,0 +1,73 @@ +锘縰sing Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DAL +{ + 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) + { + try + { + lock (lockObj) + { + filePath = $@"{filePath}\webapi{DateTime.Now.ToString("yyyyMMdd")}.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 + } +} diff --git "a/DAL/\351\207\207\350\264\255\347\256\241\347\220\206/ClsCg_POInStockBill.cs" "b/DAL/\351\207\207\350\264\255\347\256\241\347\220\206/ClsCg_POInStockBill.cs" index f665791..ec69dc0 100644 --- "a/DAL/\351\207\207\350\264\255\347\256\241\347\220\206/ClsCg_POInStockBill.cs" +++ "b/DAL/\351\207\207\350\264\255\347\256\241\347\220\206/ClsCg_POInStockBill.cs" @@ -527,7 +527,6 @@ } } - } } -- Gitblit v1.9.1