//记录日志
public static void WriteLog(string str)
{
//获取应用程序的当前工作目录
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Log\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
filePath = filePath + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
using (StreamWriter streamWriter = new StreamWriter(filePath, append: true, Encoding.UTF8))
{
streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + str);
streamWriter.Close();
streamWriter.Dispose();
}
}
C#添加日志文件——简洁(部署IIS也可以生成日志)
于 2023-10-08 16:31:38 首次发布