Php io operations C # codepublicstaticvoidWriteLog (stringmsg) {using (System. IO. StreamWriterreader = newSystem. IO. StreamWriter (System. Web. HttpC php io operations
C # code
public static void WriteLog(string msg) { using (System.IO.StreamWriter reader = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/log.txt"), true, Encoding.UTF8)) { reader.WriteLine(msg + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } }
I'm desperate. I wrote it in notepad without a breakpoint.
I/O in php is not familiar with that man. he turned this into an equivalent php code.
------ Solution --------------------
File_put_contents (realpath ('~ /Log.txt '), $ msg. date ('Y-m-d H: I: s ));
------ Solution --------------------
The code is concise.
------ Solution --------------------
Discussion
File_put_contents (realpath ('~ /Log.txt '), $ msg. date ('Y-m-d H: I: s ));
------ Solution --------------------
Discussion
Will not be automatically created if the file does not exist?