Add lock to chatlog file (#1488)

This commit is contained in:
ReinforceZwei 2021-03-07 14:20:54 +08:00 committed by GitHub
parent 771a5b9e08
commit 4853871ea1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ namespace MinecraftClient.ChatBots
private bool savePrivate = true;
private bool saveInternal = true;
private string logfile;
private object logfileLock = new object();
/// <summary>
/// This bot saves the messages received in the specified file, with some filters and date/time tagging.
@ -112,7 +113,8 @@ namespace MinecraftClient.ChatBots
{
if (dateandtime)
tosave = GetTimestamp() + ' ' + tosave;
lock (logfileLock)
{
string directory = Path.GetDirectoryName(logfile);
if (!String.IsNullOrEmpty(directory) && !Directory.Exists(directory))
Directory.CreateDirectory(directory);
@ -124,4 +126,5 @@ namespace MinecraftClient.ChatBots
stream.Close();
}
}
}
}