两个应用 reading/writing 同一个文本文件

Two apps reading/writing the same text file

我有一个 Windows 将日志写入文本文件的服务应用程序,然后我有一个需要从文件中读取相同信息的 WinForms 应用程序。

但是我怎样才能让两个应用程序(在同一个解决方案中)read/write 同一个文件? 这两个应用程序在同一解决方案中使用共享项目,但

System.AppDomain.CurrentDomain.BaseDirectory + @"\log.txt";

两者都指向不同的目录。

对于通用路径,请尝试使用:

string folderPath1 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
// or 
string folderPath2 = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);