using System;
using System.IO;
using System.Text;
namespace Common
{
public static class MsgLog
{
#region 公共变量
public static string Path { get; set; }
#endregion
#region 公共函数
public static void ClearLog()
{
if (File.Exists(Path)) File.Delete(Path);
}
public static void Log(object message)
{
var fs = getFile(Path, FileMode.Append);
var buff = Encoding.UTF8.GetBytes(message + "\r\n");
fs.Write(buff, 0, buff.Length);
fs.Close();
}
#endregion
#region 私有函数
static FileStream getFile(string filePath, FileMode mode)
{
var path = filePath.Substring(0, filePath.LastIndexOf("/", StringComparison.Ordinal));
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
var file = !File.Exists(filePath) ? new FileStream(filePath, FileMode.Create) : new FileStream(filePath, mode);
return file;
}
#endregion
}
}