public static void WriteLog(string FileName, string sMessage)
{
try
{
if (FileName == "MTNRBT")
{
if (ConfigurationManager.AppSettings["ENABLE_LOG"] == null || ConfigurationManager.AppSettings["ENABLE_LOG"].ToUpper() != "T") return;
}
if (sMessage.ToLower() != "thread was being aborted.")
{
string FilePath = ConfigurationManager.AppSettings["ERRORLOG"] + "\\" + DateTime.Now.ToString("MMM") + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("ddMMMyyyy");
if (!Directory.Exists(FilePath)) Directory.CreateDirectory(FilePath);
FilePath = FilePath + "\\" + FileName + ".txt";
if (File.Exists(FilePath))
{
FileInfo sfInfo = new FileInfo(FilePath);
if (sfInfo.Length > 524288)
{
File.Move(FilePath, FilePath.Replace(".txt", "") + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt");
}
sfInfo = null;
}
StreamWriter sw;
sw = File.AppendText(FilePath);
sw.WriteLine("****************" + DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + "**********************");
sw.WriteLine(sMessage);
sw.WriteLine("");
sw.Close();
sw = null;
}
}
catch
{
}
}
{
try
{
if (FileName == "MTNRBT")
{
if (ConfigurationManager.AppSettings["ENABLE_LOG"] == null || ConfigurationManager.AppSettings["ENABLE_LOG"].ToUpper() != "T") return;
}
if (sMessage.ToLower() != "thread was being aborted.")
{
string FilePath = ConfigurationManager.AppSettings["ERRORLOG"] + "\\" + DateTime.Now.ToString("MMM") + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("ddMMMyyyy");
if (!Directory.Exists(FilePath)) Directory.CreateDirectory(FilePath);
FilePath = FilePath + "\\" + FileName + ".txt";
if (File.Exists(FilePath))
{
FileInfo sfInfo = new FileInfo(FilePath);
if (sfInfo.Length > 524288)
{
File.Move(FilePath, FilePath.Replace(".txt", "") + "-" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt");
}
sfInfo = null;
}
StreamWriter sw;
sw = File.AppendText(FilePath);
sw.WriteLine("****************" + DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + "**********************");
sw.WriteLine(sMessage);
sw.WriteLine("");
sw.Close();
sw = null;
}
}
catch
{
}
}
No comments:
Post a Comment