using System; using System.IO; using System.Text; using Forks.Utils.IO; using TSingSoft.WebPluginFramework; namespace BWP.ABCClient { public class AbcLog { private readonly string _filePath; private readonly StringBuilder _msg = new StringBuilder(); public AbcLog(string type) { #if DEBUG _filePath = Path.Combine("../../abclog/", DateTime.Today.ToString("yyyyMMdd") + type + "log.txt"); #else _filePath = Path.Combine(Wpf.Settings.ConfigFolder + "../../abclog/", DateTime.Today.ToString("yyyyMMdd") + type + "log.txt"); #endif if (!FS.FileExists(_filePath)) FS.CreateDirectory(Path.GetDirectoryName(_filePath)); } public void Add(string msg) { _msg.Append(msg); } public void AddNewLine(string msg) { _msg.AppendLine(); _msg.Append(string.Format("{0} {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg)); } public void Commit() { try { File.AppendAllText(_filePath, _msg.ToString(), Encoding.UTF8); _msg.Clear(); } catch (Exception) { } } public string Load() { return File.ReadAllText(_filePath, Encoding.UTF8); } public void Clear() { FS.WriteAllText(_filePath, string.Empty); } } }