mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-22 01:02:16 -05:00
Kp2aLog.cs: thread safe file access
This commit is contained in:
parent
28fb854fb1
commit
85e6a0e9c2
@ -26,16 +26,29 @@ 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)
|
||||
{
|
||||
using (var streamWriter = File.AppendText(LogFilename))
|
||||
lock (_fileLocker)
|
||||
{
|
||||
string stringToLog = DateTime.Now+":"+DateTime.Now.Millisecond+ " -- " + message;
|
||||
streamWriter.WriteLine(stringToLog);
|
||||
try
|
||||
{
|
||||
using (var streamWriter = File.AppendText(LogFilename))
|
||||
{
|
||||
string stringToLog = DateTime.Now + ":" + DateTime.Now.Millisecond + " -- " + message;
|
||||
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