i want to create a simple log file for and adding frames.
here is what i found so far.>br>
this class invoked from another class which is executed in looping, so everytime the loop end it will call this calss and this class will write a log(data created in time). But, all i got is everytime a new string written in txt file it only replace the first one.
how can i add a new string in new line without replacing the old one?
i read the environment.newline but i dont get it.
private void logFile()
{
StreamWriter logfile = null;
logfile = File.CreateText(Server.MapPath("/CCTV_Files/log.txt"));
try
{
logfile.Write(String.Format("{0:yyyyMMdd_hhmmss}", DateTime.Now) + " Frame added");
}
catch (IOException e)
{
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
if (logfile != null)
{
logfile.Close();
}
}
}
Use File.AppendText:
instead of File.CreateText: