Nonsense don't say that directly on the code
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceutilities{ Public classTxtloghelper {/// <summary> ///txt logging of certain operations/// </summary> Public Static voidLogbackup (stringlogstring) { stringLogFolder =Getorcreatelogfilepath (); stringLogFile =Getbackuplogfilename (); FileInfo file=NewFileInfo (LogFile); FileStream FS=file. Open (Filemode.append, FileAccess.Write); byte[] bytes =Encoding.UTF8.GetBytes (logstring); Fs. Write (Bytes,0, Bytes. Length); Fs. Flush (); Fs. Close (); Fs. Dispose (); } //Gets the backup directory path, if it does not exist, creates the Private Static stringGetorcreatelogfilepath () {stringBackupFolder = System.Environment.CurrentDirectory +"\\log"; if(!directory.exists (BackupFolder)) Directory.CreateDirectory (BackupFolder); returnBackupFolder; } Private Static stringGetbackuplogfilename () {//to prevent excessive data volume, generate a log file daily by date stringLogfileid = DateTime.Now.ToString ("YYYY-MM-DD"); returnGetorcreatelogfilepath () +"\\"+ Logfileid +". txt"; } }}
20181015 record a simple TXT log class