|
- 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() { }
-
- /// <summary>
- /// 保存日志信息
- /// </summary>
- /// <param name="info"></param>
- public void SaveLogInfo(string info, string name)
- {
- if (info?.Length > 0)
- {
- Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance.FilePath}\\OrderInfoLog"));
- string path = $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance.FilePath}\\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();
- }
- }
-
- public string ReadTextInfo()
- {
- Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile"));
- string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt";
- FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
- StreamReader sr = new StreamReader(fs);
- string GetStr = sr.ReadLine();
- if (GetStr == null) GetStr = string.Empty;
- sr.Close();
- fs.Close();
- return GetStr;
- }
-
- public void WriteTextInfo(string info)
- {
- Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile"));
- string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt";
- FileStream fs = new FileStream(path, FileMode.Create);
- StreamWriter sw = new StreamWriter(fs);
- sw.WriteLine(info);
- sw.Close();
- fs.Close();
- }
-
- }
- }
|