Skip to content

Commit 07ef1be

Browse files
committed
Update FileLogger.cs
1 parent d2bc586 commit 07ef1be

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/Files.Shared/Utils/Logger/FileLogger.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3434
if (formatter is null)
3535
return;
3636

37-
lock (syncRoot)
37+
try
3838
{
39-
try
39+
var message = exception?.ToString() ?? formatter(state, exception);
40+
41+
lock (syncRoot)
4042
{
41-
var message = exception?.ToString() ?? formatter(state, exception);
42-
4343
File.AppendAllText(filePath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.ffff}|{logLevel}|{message}" + Environment.NewLine);
4444
}
45-
catch (Exception e)
46-
{
47-
Debug.WriteLine($"Writing to log file failed with the following exception:\n{e}");
48-
}
45+
}
46+
catch (Exception e)
47+
{
48+
Debug.WriteLine($"Writing to log file failed with the following exception:\n{e}");
4949
}
5050
}
5151

@@ -54,9 +54,9 @@ public void PurgeLogs(int numberOfLinesKept)
5454
if (!File.Exists(filePath))
5555
return;
5656

57-
lock (syncRoot)
57+
try
5858
{
59-
try
59+
lock (syncRoot)
6060
{
6161
var lines = File.ReadAllLines(filePath);
6262
if (lines.Length > numberOfLinesKept)
@@ -65,10 +65,10 @@ public void PurgeLogs(int numberOfLinesKept)
6565
File.WriteAllLines(filePath, lastLines);
6666
}
6767
}
68-
catch (Exception e)
69-
{
70-
Debug.WriteLine($"Purging the log file failed with the following exception:\n{e}");
71-
}
68+
}
69+
catch (Exception e)
70+
{
71+
Debug.WriteLine($"Purging the log file failed with the following exception:\n{e}");
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)