日志文件抛出错误,已在使用中 [英] Log file throwing error, already in use
问题描述
我正在尝试将错误记录到Application文件夹(其Windows应用程序)中。我想要做的是首先检查一个文件是否存在,如果没有创建一个新文件或它是否存在将错误写入文件。
但我面临的问题是路径的文件。我希望日志位于bin内的Log文件夹中。但我怎么能访问它。如果我接受Applcation.StartUp,它进入调试文件夹,因为正在完成该过程,文件写入失败并显示错误文件已在使用中。
那么我该如何处理呢。我想要的路径... \\\日期..
谢谢
Hi, i am trying to log error into a Application folder(its windows app). What i am trying to do is first check whether a file exists , if not create a new file or if it does exists write the error to the file.
But the problem i am facing is that the path of file. I want the Logs to be in Log folder inside bin. But how can i access that. If i take Applcation.StartUp it goes inside the debug folder and since the process is being done the file writing fails with the error"File already in use".
So how can i handle this. My desired path in ...\bin\Log..
Thanks
推荐答案
使用一个现有的组件,如 log4net
或我的文章:针对log4net的迷你直接替换 [ ^ ]
Use an existing component like log4net
or my article : Mini Drop-in Replacement for log4net[^]
您好b $ b
你可以尝试这个来访问bin里面的日志文件夹吗?
Hi
Can you try this to access the log folder inside bin?
string execPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
DirectoryInfo diInfo = Directory.GetParent(execPath);
string logPath = Path.Combine(diInfo.Parent.FullName, "logs");
问候
Dominic
Regards
Dominic
这篇关于日志文件抛出错误,已在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!