Monday, December 10, 2007

Write Log file. After specified file size save as it as

public void createLog(string msg)
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/OpenActiityLog.txt"));
FileInfo f = new FileInfo(Server.MapPath("~/OpenActiityLog.txt"));
int i = Convert.ToInt32(f.Length.ToString());

if (i < sw =" new" date="">" + DateTime.Now.ToString() + "- " + msg.ToString());
sw.WriteLine();
sw.WriteLine("============================================================================================");
sw.WriteLine();
sw.Flush();
sw.Close();
}
else
{
string sdate = System.DateTime.Today.ToShortDateString();
string temp = sdate.Replace('/', '-');
f.CopyTo(Server.MapPath("~/OpenActiityLog.txt") + temp + ".txt", true);


StreamWriter sw = new StreamWriter(Server.MapPath("~/OpenActiityLog.txt"), false);
sw.WriteLine("Date=>" + DateTime.Now.ToString() + "- " + msg.ToString());
sw.WriteLine();
sw.WriteLine("============================================================================================");
sw.WriteLine();
sw.Flush();
sw.Close();

}

No comments: