首页 > 代码库 > c#写日志的函数

c#写日志的函数

public class LogClass
{
  public void Write(string content)
  {
    try
    {
    var directoryPath = System.Windows.Forms.Application.StartupPath;
    var filePath = directoryPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "a.log";
    File.AppendAllText(filePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    File.AppendAllText(filePath, Environment.NewLine);
    File.AppendAllText(filePath, content);
    File.AppendAllText(filePath, Environment.NewLine);
    }
   catch (Exception ex)
    {
      Console.Write(ex.ToString());
    }
  }
}

c#写日志的函数