The data is written to a local file

       In normal development, the test may be encountered within the network no problem, but when the update will complain to the external network, then we can not be debugged outside the network. If we analyze the complete business problem that may arise or can not be the cause of the error, then you can add exception handling in key areas, and then the key point of the exception or write a text, according to the analysis of log information printed out, there help us to find the problem.

. 1  ///  <Summary> 
2  /// log
 . 3  ///  </ Summary> 
. 4  ///  <param name = "LogString"> </ param> 
. 5  public  static  void AddLgoToTXT ( String LogString)
 . 6  {
 . 7      / / log file storage path 
. 8      String dirName = " servicelog " ;
 . 9      String dirpath is AppDomain.CurrentDomain.BaseDirectory + = dirName;
 10      IF (! Directory.Exists (dirpath is))
 . 11      {
 12 is         Directory.CreateDirectory (dirpath is);
 13 is      }
 14      // date format log day 
15      String path = dirpath is + " / " + DateTime.Now.ToString ( " yyyyMMdd " ) + " .txt " ;
 16      IF (! System.IO.File.Exists (path))
 . 17      {
 18 is          the FileStream Stream = System.IO.File.Create (path);
 . 19          stream.Close ();
 20 is          stream.Dispose ();
 21 is      }
 22 is      // the append: to true to append data to the file; false overwrite the file
23     using (StreamWriter writer = new StreamWriter(path ,true))
24     {
25         writer.WriteLine(logstring);
26     }
27 }

 

Guess you like

Origin www.cnblogs.com/qinaqina/p/11615618.html