You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

61 lines
1.2 KiB

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);
}
}
}