Log File creation for web application

public string logPath = ConfigurationManager.AppSettings["LogPath"] + DateTime.Now.ToString("MM-dd-yyyy")+".txt";
public string logStatus;

logStatus = " Created! \t:" + DateTime.Now.ToString("hh:mm:ss");
if (!File.Exists(logPath))
{
File.WriteAllText(logPath, logStatus);
logStatus = System.Environment.NewLine;
logAppending(logStatus);
}
else
{
logAppending(logStatus);
}

logAppending
---------------
private void logAppending(string allStatus)
{
StreamWriter sw = new StreamWriter(logPath, true);
sw.WriteLine(allStatus + System.Environment.NewLine);
sw.Close();
}


...S.VinothkumaR.

No comments: