delphi 写日志文件I/O error 32
我写了一个函数用来写日志,但是写的时候提示出错。I/Oerror32。我查了下错误原因应该是定时器同时写入的问题,然后我用了2中线程方法处理,但是都没用,结果一样,帮忙看...
我写了一个函数用来写日志,但是写的时候提示出错。I/O error 32。我查了下错误原因应该是定时器同时写入的问题,然后我用了2中线程方法处理,但是都没用,结果一样,帮忙看下怎么回事。
procedure TEventLog.RecordLog(Log: string);
var
f:Textfile;
FileName:string;
name:string;
begin
if WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 then
begin
name:=FormatDateTime('yyyymmdd',now);
FileName:=ExtractFilePath(Paramstr(0))+'log\'+name+'.log'; //保存文件名
AssignFile(f, FileName);
try
if FileExists(FileName)= False then
Rewrite(f)
else
Append(f);
Writeln(f,FormatDateTime('yy''-''mm''-''dd hh:nn:ss ',Now) + Log);
finally
CloseFile(f);
end;
ReleaseMutex(hMutex);
end;
end;
procedure TEventLog.RecordLog(Log: string);
var
f:Textfile;
FileName:string;
name:string;
begin
criticalsection.enter;
try
name:=FormatDateTime('yyyymmdd',now);
FileName:=ExtractFilePath(Paramstr(0))+'log\'+name+'.log'; //保存文件名
AssignFile(f, FileName);
try
if FileExists(FileName)= False then
Rewrite(f)
else
Append(f);
Writeln(f,FormatDateTime('yy''-''mm''-''dd hh:nn:ss ',Now) + Log);
finally
CloseFile(f);
end;
finally
criticalsection.leave;
end;
end; 展开
procedure TEventLog.RecordLog(Log: string);
var
f:Textfile;
FileName:string;
name:string;
begin
if WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 then
begin
name:=FormatDateTime('yyyymmdd',now);
FileName:=ExtractFilePath(Paramstr(0))+'log\'+name+'.log'; //保存文件名
AssignFile(f, FileName);
try
if FileExists(FileName)= False then
Rewrite(f)
else
Append(f);
Writeln(f,FormatDateTime('yy''-''mm''-''dd hh:nn:ss ',Now) + Log);
finally
CloseFile(f);
end;
ReleaseMutex(hMutex);
end;
end;
procedure TEventLog.RecordLog(Log: string);
var
f:Textfile;
FileName:string;
name:string;
begin
criticalsection.enter;
try
name:=FormatDateTime('yyyymmdd',now);
FileName:=ExtractFilePath(Paramstr(0))+'log\'+name+'.log'; //保存文件名
AssignFile(f, FileName);
try
if FileExists(FileName)= False then
Rewrite(f)
else
Append(f);
Writeln(f,FormatDateTime('yy''-''mm''-''dd hh:nn:ss ',Now) + Log);
finally
CloseFile(f);
end;
finally
criticalsection.leave;
end;
end; 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询