using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HBLConsole.Service { public class TextHelper { private volatile static TextHelper _Instance; public static TextHelper GetInstance => _Instance ?? (_Instance = new TextHelper()); private TextHelper() { } /// /// 保存日志信息 /// /// public void SaveLogInfo(string info, string name) { if (info?.Length > 0) { Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\OrderInfoLog")); string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\OrderInfoLog\\{DateTime.Now.ToString("yyyy-MM-dd") + " " + name}.txt"; StringBuilder sb = new StringBuilder(); sb.Append($"****************************************** {DateTime.Now} ******************************************" + "\n"); sb.Append(info); sb.Append("**********************************************************************************************************" + "\n\n"); FileStream fs = new FileStream($"{path}", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(sb.ToString()); sw.Close(); fs.Close(); } } } }