class alertLog
{
private static alertLog log =
null;
private string logFile =
null;
private string logPath =
null;
private alertLog()
{
DateTime now = DateTime.Now;
logFile = now.ToLongDateString().ToString();
logPath = Directory.GetCurrentDirectory() +
"\\log";
System.IO.Directory.CreateDirectory(logPath);
}
public static alertLog
getInstance()
{
if (
null == log)
{
lock(
new object())
{
if (
null == log)
{
log =
new alertLog();
}
}
}
return log;
}
public void wrightLog(
string str)
{
lock (
new object())
{
DateTime now = DateTime.Now;
string date = now.ToLongDateString().ToString();
string time = now.ToLongTimeString().ToString();
string strTobeWrighted =
"[" + date +
" " + time +
"] " + str +
"\r\n";
using (System.IO.FileStream fs = System.IO.File.OpenWrite(
string.Format(
"{0}\\{1}.txt", logPath, logFile)))
{
byte[] data = System.Text.Encoding.Default.GetBytes(strTobeWrighted);
fs.Position = fs.Length;
fs.Write(data,
0, data.Length);
fs.Close();
}
}
}
}