|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace NetLibrary.Log
|
|
|
|
|
{
|
|
|
|
|
public class ErrorFollow
|
|
|
|
|
{
|
|
|
|
|
public static bool IsDebug = true;
|
|
|
|
|
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void TraceWrite(string TypeName, string StackTrace, string ErrorMsg)
|
|
|
|
|
{
|
|
|
|
|
if (ErrorFollow.IsDebug == false) return;
|
|
|
|
|
if (string.IsNullOrEmpty(ErrorMsg) == true) ErrorMsg="<22><>ϢΪ<CFA2><CEAA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string DirectoryName = AppDomain.CurrentDomain.BaseDirectory + "ServerCookies";
|
|
|
|
|
if (Directory.Exists(DirectoryName) == false) Directory.CreateDirectory(DirectoryName);
|
|
|
|
|
string filePath = DirectoryName + "/" + DateTime.Today.ToString("yyyy-MM-dd") + "EventLog.log";
|
|
|
|
|
bool append = true;
|
|
|
|
|
if (File.Exists(filePath) == false) File.Create(filePath).Close();
|
|
|
|
|
FileInfo f = new FileInfo(filePath);
|
|
|
|
|
if (f.Length / 1024 / 1024 > 1)
|
|
|
|
|
{
|
|
|
|
|
append = false;
|
|
|
|
|
string newFile=DirectoryName+"/"+DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log";
|
|
|
|
|
f.CopyTo(newFile, true);
|
|
|
|
|
}
|
|
|
|
|
f = null;
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(filePath, append, System.Text.Encoding.Default))
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("------------");
|
|
|
|
|
sw.WriteLine(TypeName);
|
|
|
|
|
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
sw.WriteLine(StackTrace);
|
|
|
|
|
sw.WriteLine(ErrorMsg);
|
|
|
|
|
sw.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void TraceWrite(string filePath, string TypeName, string StackTrace, string ErrorMsg)
|
|
|
|
|
{
|
|
|
|
|
if (ErrorFollow.IsDebug == false) return;
|
|
|
|
|
if (string.IsNullOrEmpty(ErrorMsg) == true) ErrorMsg = "δ֪<CEB4><D6AA><EFBFBD><EFBFBD>";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
bool append = true;
|
|
|
|
|
if (File.Exists(filePath) == false) File.Create(filePath).Close();
|
|
|
|
|
FileInfo f = new FileInfo(filePath);
|
|
|
|
|
if (f.Length / 1024 / 32 > 10) append = false;
|
|
|
|
|
f = null;
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(filePath, append, System.Text.Encoding.Default))
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("------------");
|
|
|
|
|
sw.WriteLine(TypeName);
|
|
|
|
|
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
sw.WriteLine(StackTrace);
|
|
|
|
|
sw.WriteLine(ErrorMsg);
|
|
|
|
|
sw.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
public static void DeleteLog(int Day)
|
|
|
|
|
{
|
|
|
|
|
string DirectoryName = AppDomain.CurrentDomain.BaseDirectory + "ServerCookies/";
|
|
|
|
|
if (Directory.Exists(DirectoryName) == false) return;
|
|
|
|
|
string[] files = Directory.GetFiles(DirectoryName, "*.log");
|
|
|
|
|
foreach (string filePath in files)
|
|
|
|
|
{
|
|
|
|
|
DateTime dt = File.GetCreationTime(filePath);
|
|
|
|
|
if (dt.AddDays(Day) > DateTime.Now) continue;
|
|
|
|
|
File.Delete(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|