mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-25 18:52:19 -05:00
Kp2aLog.cs: thread safe file access
This commit is contained in:
parent
28fb854fb1
commit
85e6a0e9c2
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user