Skip to content

Commit 7a74cf4

Browse files
cjhillbrandCJ Hillbrand
andauthored
Introduce Default Behavior to Clear out Old Summary Log File (#522)
* Allow for user to write a brand new summary file. Default is to write to new file. * Also make sure that the file upload monitor looks for the right file. * remove additional constructor. * Remove string interpolation designation from summary file string. * Update to version 2.0.22 --------- Co-authored-by: CJ Hillbrand <cjhillbrand@microsoft.com>
1 parent 6d887a5 commit 7a74cf4

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.21
1+
2.0.22

src/VirtualClient/VirtualClient.Core/Logging/SummaryFile/SummaryFileLogger.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace VirtualClient.Logging
3030
/// </summary>
3131
public class SummaryFileLogger : ILogger, IFlushableChannel, IDisposable
3232
{
33+
internal const string DefaultFileName = "summary.txt";
3334
internal const int MaxLineLength = 250;
3435
private static readonly Encoding ContentEncoding = Encoding.UTF8;
3536
private static readonly string DashLine = new string('-', 100);
@@ -57,10 +58,7 @@ public SummaryFileLogger(string filePath, IAsyncPolicy retryPolicy = null)
5758
if (string.IsNullOrWhiteSpace(filePath))
5859
{
5960
PlatformSpecifics tempPlatformSpecifics = new PlatformSpecifics(Environment.OSVersion.Platform, RuntimeInformation.ProcessArchitecture);
60-
ISystemInfo systemInfo = new SystemManagement();
61-
string experimentId = systemInfo.ExperimentId;
62-
string suffix = string.IsNullOrEmpty(experimentId) ? string.Empty : $"-{experimentId}";
63-
filePath = tempPlatformSpecifics.Combine(tempPlatformSpecifics.LogsDirectory, $"summary{suffix}.txt");
61+
filePath = tempPlatformSpecifics.Combine(tempPlatformSpecifics.LogsDirectory, DefaultFileName);
6462
}
6563

6664
this.filePath = filePath;
@@ -464,6 +462,11 @@ await this.fileAccessRetryPolicy.ExecuteAsync(async () =>
464462
{
465463
await this.semaphore.WaitAsync();
466464

465+
if (this.fileSystem.File.Exists(this.filePath))
466+
{
467+
await this.fileSystem.File.DeleteAsync(this.filePath);
468+
}
469+
467470
using (FileSystemStream fileStream = this.fileSystem.FileStream.New(this.filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
468471
{
469472
if (fileStream.Length == 0)

src/VirtualClient/VirtualClient.Monitors/FileUploadMonitor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ private async Task UploadSummaryFileAsync(IBlobManager blobManager, EventContext
240240
{
241241
try
242242
{
243-
string suffix = string.IsNullOrEmpty(this.ExperimentId) ? string.Empty : $"-{this.ExperimentId}";
244-
string summaryTxtFileLocation = Path.Combine(this.PlatformSpecifics.LogsDirectory, $"summary{suffix}.txt");
243+
string summaryTxtFileLocation = Path.Combine(this.PlatformSpecifics.LogsDirectory, "summary.txt");
245244
bool summaryTxtFileExists = this.fileSystem.File.Exists(summaryTxtFileLocation);
246245
telemetryContext
247246
.AddContext(nameof(summaryTxtFileLocation), summaryTxtFileLocation)

0 commit comments

Comments
 (0)