In order to run the program on the server in a timely manner to track the error, you can add the program to write the log where necessary.
stringfolder =string. Format (@"D:\\{0}\\{1}", DateTime.Now.ToString ("yyyy"), DateTime.Now.ToString ("MM")); //determine if a folder exists if(!directory.exists (folder)) {directory.createdirectory (folder); } Try{File.writealltext (string. Format ("{0}\\{1}.txt", folder, DateTime.Now.ToString ("YYYYMMDD")),"Test information overwrites write information to the file", Encoding.UTF8); //working with text lines before writing text to a file//StreamWriter a parameter overrides by default//StreamWriter The second argument is false to overwrite the existing file, true to append the text to the end of the file using(StreamWriter file =NewStreamWriter (string. Format ("{0}\\{1}.txt", folder, DateTime.Now.ToString ("DD")),true) ) {file. WriteLine ("The test information is appended to the file");//append directly to end of file, no line breakFile. WriteLine ("---------------------------------"); File. WriteLine ();//append directly to the end of the file, line wrapfile. Close (); } } Catch(Exception) {Throw; }
C # Delete all files under the specified folder and keep folders
New DirectoryInfo (path); if (dir. Exists) { = dir. GetDirectories (); foreach inch Childs) {Child . Delete (true); Dir. Delete (true);
C # writes log information to a file