可能在ServiceBase应用程序内写入文件... [英] Problens to write a file inside a ServiceBase app...

查看:84
本文介绍了可能在ServiceBase应用程序内写入文件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个文件,并将日志文件追加到ServiceBase扩展类的start()方法内...

I'm trying to write a a file, log file append inside the start() method of ServiceBase extended Class...

但是我在这里进行测试,执行此代码时出现错误:

But I´m  testing here and the I got a error when this code is executed:

StreamWriter sw = new StreamWriter(getLogFilePath(), true);
sw.WriteLine(mensagem);
sw.Flush();
sw.Close();  


如果我执行此代码,则不会出现任何错误,但文件未附加:

If I do this code, I gotr no error but the file is not appened:

File.WriteAllText(getLogFilePath(), mensagem);

可以是什么?如何解决问题?
谢谢大家!

What can be? How to solve the problem?
Thanks all!

推荐答案

您遇到的错误是什么?

What is the error that you are getting?

File.WriteAllText(getLogFilePath(), mensagem);


将始终创建一个新文件: http://msdn.microsoft.com/zh-cn/library/system.io.file.writealltext.aspx


will always create a new file: http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx


这篇关于可能在ServiceBase应用程序内写入文件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆