This error started occurring at high volume installations when SMB1 is disabled. The process cannot access the file ‘user1.Log.txt’ because it is being used by another process. The logs are by user, and this happens only if there are multiple users, which doesn’t make sense. The multiple application can write to the log file, so they are opened with share lock. The logs are accessed by C++Builder and .Net application, but so far all of the errors seems coming from .net. Also application is shared accross users via Citrix. Any idea why SMB2/3 causes the error to happen?
C++Builder
StreamWriter = new TStreamWriter(new TFileStream(FileNameAndPath, fmOpenWrite |
fmShareDenyNone), TEncoding::UTF8, 1024);
C#
using (var stream = File.Open(path, FileMode.Append, FileAccess. Write, FileShare. ReadWrite))
using (var streamWriter = new StreamWriter(stream))
using (var writer = TextWriter. Synchronized(streamWriter))
{
if (stream.Length == 0)
{
writer.WriteLine(GetLogHeader (userId, stationId));
}
// Write the message, then close the log.
writer.WriteLine(GetLogMessage (program, shortMsg, LongMsg));
}