Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a log file using text writer in C#, But I want to append the date and time whenever the file is executed.

How to do this.
Posted

use the below code
File.AppendAllText("YourPath", "Your matter which you want in the text file " + DateTime.Now().ToString("dd/MM/yyyy hh:mm:ss"));
 
Share this answer
 
StreamWriter objsw = new StreamWriter("D:\\AppLog.txt");

objsw.WriteLine(DateTime.Now.ToLocalTime());
objsw.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900