还是Windows服务调用应用程序的问题。
所调用的应用程序会执行另外一个应用程序,成功后会写一个log文件的操作
logPath = System.Environment.CurrentDirectory + "\\service.log";
StreamWriter sw;
if (File.Exists(logPath) == false)
{
sw = File.CreateText(logPath);
} sw = File.AppendText(logPath);
string Info = "addSucceed";
sw.WriteLine(Info);
sw.Flush();
sw.Close();
应用程序单独执行的时候是可以成功执行另外的那个应用程序并写入这个Info的,服务调用应用程序后,会成功执行另外的那个应用程序,但是不会写入Info...
所调用的应用程序会执行另外一个应用程序,成功后会写一个log文件的操作
logPath = System.Environment.CurrentDirectory + "\\service.log";
StreamWriter sw;
if (File.Exists(logPath) == false)
{
sw = File.CreateText(logPath);
} sw = File.AppendText(logPath);
string Info = "addSucceed";
sw.WriteLine(Info);
sw.Flush();
sw.Close();
应用程序单独执行的时候是可以成功执行另外的那个应用程序并写入这个Info的,服务调用应用程序后,会成功执行另外的那个应用程序,但是不会写入Info...
应该使用AppDomain的方法获得服务所在的路径
并把路径写成绝对路径
然后在程序中读此配置节点值,可避免相对路径带来的不确定因素
if (File.Exists(System.Environment.CurrentDirectory + "\\service.log"))
{
logpath = System.Environment.CurrentDirectory + "\\service.log";
}
else
{
logpath = ConfigurationManager.AppSettings["LogFileFolder"] + "service.log";
}