Skip to content

Commit

Permalink
Overwrite log file by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed May 14, 2024
1 parent 92e09ec commit 8e0574f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Internal/Logging/FileLogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FileLogHandler : ILogHandler, IDisposable
/// </summary>
/// <param name="filePath">The path of the log file.</param>
public FileLogHandler(string filePath)
: this(filePath, overwrite: false)
: this(filePath, overwrite: true)
{

}
Expand Down
24 changes: 12 additions & 12 deletions dotnet/test/common/Internal/Logging/FileLogHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,52 @@ public void ShouldHandleLogEvent()
}

[Test]
public void ShouldAppendFileIfDoesNotExist()
public void ShouldCreateFileIfDoesNotExist()
{
var tempFilePath = Path.GetTempPath() + "somefile.log";
var tempFile = Path.GetTempFileName();

try
{
using (var fileLogHandler = new FileLogHandler(tempFilePath))
using (var fileLogHandler = new FileLogHandler(tempFile))
{
fileLogHandler.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message"));
}

using (var fileLogHandler2 = new FileLogHandler(tempFilePath))
using (var fileLogHandler2 = new FileLogHandler(tempFile))
{
fileLogHandler2.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message"));
}

Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message").Count, Is.EqualTo(2));
Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message").Count, Is.EqualTo(1));
}
finally
{
File.Delete(tempFilePath);
File.Delete(tempFile);
}
}

[Test]
public void ShouldAppendFileIfExists()
{
var tempFile = Path.GetTempFileName();
var tempFilePath = Path.GetTempPath() + "somefile.log";

try
{
using (var fileLogHandler = new FileLogHandler(tempFile))
using (var fileLogHandler = new FileLogHandler(tempFilePath))
{
fileLogHandler.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message"));
}

using (var fileLogHandler2 = new FileLogHandler(tempFile))
using (var fileLogHandler2 = new FileLogHandler(tempFilePath, overwrite: false))
{
fileLogHandler2.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message"));
}

Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message").Count, Is.EqualTo(2));
Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message").Count, Is.EqualTo(2));
}
finally
{
File.Delete(tempFile);
File.Delete(tempFilePath);
}
}

Expand All @@ -107,7 +107,7 @@ public void ShouldOverwriteFileIfExists()
}

[Test]
public void ShouldCreateFileIfDoesNotExist()
public void ShouldAppendFileIfDoesNotExist()
{
var tempFilePath = Path.GetTempPath() + "somefile.log";

Expand Down

0 comments on commit 8e0574f

Please sign in to comment.