Skip to content
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
11 changes: 11 additions & 0 deletions src/Microsoft.ComponentDetection.Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public Logger(IConsoleWritingService consoleWriter, IFileWritingService fileWrit

private VerbosityMode Verbosity { get; set; }

private bool Initialized { get; set; }

private bool WriteToFile { get; set; }

private bool WriteLinePrefix { get; set; }
Expand All @@ -30,10 +32,19 @@ public void Init(VerbosityMode verbosity, bool writeLinePrefix = true)
this.WriteToFile = true;
this.Verbosity = verbosity;
this.WriteLinePrefix = writeLinePrefix;

// If initialization has already completed, don't attempt to create
// the log file again as this throws an exception
if (this.Initialized)
{
return;
}

try
{
this.fileWritingService.WriteFile(LogRelativePath, string.Empty);
this.LogInfo($"Log file: {this.fileWritingService.ResolveFilePath(LogRelativePath)}");
this.Initialized = true;
}
catch (Exception)
{
Expand Down