Faillog 클래스에서 "다른 프로세스에서이 오류가 사용 중입니다."오류가 발생합니다. 그 코드는 다음과 같습니다. Log 메서드에서 "using (StreamWriter sw = new StreamWriter (path + file, true))"행에서 발생합니다. 파일에 액세스하는 것으로 보이는 것이 없기 때문에 내가 뭘 잘못하고 있는지 전혀 알지 못합니다. 프로그램이 처음 실행될 때 클래스의 인스턴스가 생성되고 2 초 후에 다른 프로세스에 의해 사용되는 것이기 때문에 불가능한 것처럼 보입니다. 이 오류의 원인을 파악하는 데 도움을 드리고 싶습니다.C# - 로그 클래스 IO 예외
class Faillog
{
#region Private Variables
//The location of the Faillog file.
private string path;
//The name of the file used for marking failures.
private string file;
#endregion
#region Constructor
public Faillog(string p = @"C:\RH Faillog\", string f = "default")
{
path = p;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (f == "default")
{
file = "Faillog_" + DateTime.Now.ToShortDateString().Replace("/", "-") + ".txt";
}
else
{
file = f;
}
if (!File.Exists(path + file))
{
File.Create(path + file);
}
}
#endregion
#region Getters
public string GetPath()
{
return path;
}
public string GetFile()
{
return file;
}
#endregion
#region Public Methods
//Logs a fail record into the file.
public void Log(string name)
{
using (StreamWriter sw = new StreamWriter(path + file, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + ": " + name + " failed.");
}
}
#endregion
http://superuser.com/questions/140643/how-to-get-the-names-of-the-programs-which-are-accessing-a-fail-file-folder-a –
스트림을 닫으십시오. – Bobby
나는 괄호 안에있는 것이 무엇이든간에 자동으로 사용하는 메소드를 삭제한다고 생각했습니다. 그것은 다른 경우에 저를 위해 일해 왔습니다. – 11clock