/// <summary> ///Create and write a log/// </summary> /// <param name= "SuccessA100" ></param> /// <param name= "Result" ></param> Public voidWritelog (list<string> SuccessA100,stringResult,stringA102) { if(SuccessA100 = =NULL) { return; } stringTxtpath = AppDomain.CurrentDomain.BaseDirectory +"log\\"+a102 +"\\"+ Result +a102. Replace ("-","") +datetime.now.tostring ("YYYYYMMDD") +". csv"; if(!file.exists (Txtpath)) { if(! Directory.Exists (AppDomain.CurrentDomain.BaseDirectory +"log\\"+A102)) {Directory.CreateDirectory (AppDomain.CurrentDomain.BaseDirectory+"log\\"+A102); } FileStream FS1=NewFileStream (Txtpath, FileMode.Create, FileAccess.Write);//Create write File using(StreamWriter SW =NewStreamWriter (FS1)) {SW. WriteLine ("A001,"); foreach(stringA100inchSuccessA100) {SW. WriteLine (A100+",");//Start Write Value} SW. Close (); FS1. Close (); } } Else{FileStream fs=NewFileStream (Txtpath, Filemode.append, FileAccess.Write); using(StreamWriter SW =NewStreamWriter (FS)) { foreach(stringA100inchSuccessA100) {SW. WriteLine (A100+",");//Start Write Value} SW. Close (); Fs. Close (); }} thread.sleep ( +); }
. NET creating and writing a CSV file