using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Engine
{
public class Logger
{
private static readonly object obj = new object();
public int iNo = 1;
/// <summary>
/// 操作日志
/// </summary>
/// <param name="s">日志能容</param>
public void WriteLog(string sValue)
{
WriteLogs(sValue, "Debug");
}
/// <summary>
/// 错误日志
/// </summary>
/// <param name="s">日志内容</param>
public void WriteError(string sValue)
{
WriteLogs(sValue, "Error");
}
public void WriteLogs(string title, string type)
{
lock (obj)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
long lMax = 0xFFFFFFF;
//long lMax = 0xF;
if (!string.IsNullOrEmpty(path))
{
DateTime dT = DateTime.Now;
path = AppDomain.CurrentDomain.BaseDirectory + "\\log\\" + dT.ToString("yyyy_MM_dd");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path += "\\" + DateTime.Now.ToString("yyyyMMdd") + "_" + type+ "_" + iNo.ToString()+ ".txt";
FileInfo info = new FileInfo(path);
if (File.Exists(path))
{
FileInfo FI = new FileInfo(path);//判断大小
if (FI.Length > lMax)
{
iNo++;
}
}
if (!File.Exists(path))
{
FileStream fs = File.Create(path);
fs.Close();
}
if (File.Exists(path))
{
StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default);
sw.WriteLine(title);
sw.Close();
}
}
}
}
}
}