Kp2aLog.cs: thread safe file access

This commit is contained in:
Philipp Crocoll 2013-08-03 12:31:40 +02:00
parent 28fb854fb1
commit 85e6a0e9c2

View File

@ -26,10 +26,16 @@ namespace keepass2android
{
private static bool? _logToFile;
private static object _fileLocker = new object();
public static void Log(string message)
{
Android.Util.Log.Debug("KP2A", message);
if (LogToFile)
{
lock (_fileLocker)
{
try
{
using (var streamWriter = File.AppendText(LogFilename))
{
@ -37,6 +43,13 @@ namespace keepass2android
streamWriter.WriteLine(stringToLog);
}
}
catch (Exception e)
{
Android.Util.Log.Debug("KP2A", "Couldn't write to log file. " + e);
}
}
}
}