1.通过流的方式

 1         public void writelog(string log)
 2         {
 3             streamwriter stream;
 4             string path = "d:/writelog/";
 5             if (!directory.exists(path))
 6             {
 7                 directory.createdirectory(path);
 8             }
 9             stream = new streamwriter(path + "addvideo.txt", true, encoding.utf8);
10             stream.writeline(datetime.now.tostring() + ":" + log);
11             stream.flush();
12             stream.close();
13         }