Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

fix(logging): Prevent IO ex concurrent writes #1057

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions NuKeeper.Inspection/Logging/FileLogger.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using NuKeeper.Abstractions.Logging;
using System;
using System.IO;
using NuKeeper.Abstractions.Logging;

namespace NuKeeper.Inspection.Logging
{
public class FileLogger : IInternalLogger
{
private readonly object _fileLocker = new object();
private readonly string _filePath;
private readonly LogLevel _logLevel;

Expand Down Expand Up @@ -46,8 +47,9 @@ public void Log(LogLevel level, string message)

private void WriteMessageToFile(string message)
{
using (var w = File.AppendText(_filePath))
lock (_fileLocker)
{
using var w = File.AppendText(_filePath);
w.WriteLine(message);
}
}
Expand Down