나는 파일에 어떤 것을 쓰는 asp.net 2.0의 웹 사이트를 가지고있다. 그러나 다른 사용자가 해당 사이트를 방문하면 동시에 두 번째 파일을 사용한 작업을 완료 할 때까지 파일의 첫 번째 작업이 완료 될 때까지 작동하지 않습니다. 이러한 상황을 처리하는 방법.수행 방법 단일 파일에서 다중 쓰기 opeartion?
AppConfiguration appConfiguration = new AppConfiguration();
string LogFile =String.Empty;
string sLogFormat =string.Empty;
string sErrorTime =string.Empty;
StreamWriter sw=null;
public LogManager()
{
if(!File.Exists(AppConfiguration.LogFilePath))
{
Directory.CreateDirectory(AppConfiguration.LogFilePath);
}
LogFile = AppConfiguration.LogFilePath+"WAP"+sErrorTime + ".log";
if(!File.Exists(LogFile))
{
File.Create(LogFile);
}
}
public void closeStream()
{
if(sw != null)
{
sw.Close();
}
}
public void LogException(string className,string methodName, string errorMessage)
{
try
{
if(!File.Exists(LogFile))
{
File.Create(LogFile);
}
sw = new StreamWriter(LogFile,true);
sw.WriteLine(DateTime.Now.ToString() + " | " + className + ":" + methodName + ":"+ errorMessage);
sw.Flush();
sw.Close();
}
catch(Exception)
{
if(sw != null)
{
sw.Close();
}
}
}
@Sandy; 이 문제가 발생하는 이유는 코드에 따라 다릅니다. 그 중 일부를 우리와 공유 할 수 있습니까? – BeemerGuy
스레드 및 잠금 –
로그 파일을 SQL 데이터베이스의 테이블로 바꾸어야합니다. – SLaks