Collect error log methods

Time:2019-6-5
public static void WriteLog(string log)
{
 fw = null;
  //string filePath = Directory.GetCurrentDirectory();
  string filePath =.CurrentDomain.BaseDirectory;
  if (!filePath.EndsWith(@"\Resource"))
  {
      filePath = filePath + "Resource";
  }
  string fileName = filePath + "\log.txt";
  try
  {
      if (.Exists(fileName))
      {
          fw =.AppendText(fileName);
      }
      else
      {
          fw =.CreateText(fileName);
      }
      fw.WriteLine(log);
  }
  catch ( e) { }
  finally
  {
      if (fw != null)
      {
          try { fw.Close(); } catch ( e1) { }
      }
  }
}
// There is a log. TXT file under the Resource folder for logging errors

Called in other methods:

WriteLog (“Time:”+. Now. ToString ()));
WriteLog (“XXX method error”);
WriteLog(“Error:” + e.ToString().Trim());