string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + $"/log{DateTime.Now.ToString("yyyyMMdd")}.log";
if (!File.Exists(path))
{
File.Create(path).Dispose(); //创建完文件之后,要把资源释放掉,才能继续往文件里书写内容
}
原文:https://www.cnblogs.com/sayunara/p/14654888.html