diff --git a/src/shared/Core/Trace2FileWriter.cs b/src/shared/Core/Trace2FileWriter.cs index 47f1bf19c..dbf1b5d6d 100644 --- a/src/shared/Core/Trace2FileWriter.cs +++ b/src/shared/Core/Trace2FileWriter.cs @@ -1,4 +1,5 @@ using System.IO; +using System; namespace GitCredentialManager; @@ -13,6 +14,22 @@ public Trace2FileWriter(Trace2FormatTarget formatTarget, string path) : base(for public override void Write(Trace2Message message) { - File.AppendAllText(_path, Format(message)); + try + { + File.AppendAllText(_path, Format(message)); + } + catch (DirectoryNotFoundException) + { + // Do nothing, as this either means we don't have the + // parent directories above the file, or this trace2 + // target points to a directory. + } + catch (UnauthorizedAccessException) + { + // Do nothing, as this either means the file is not + // accessible with current permissions, or we are on + // Windows and the file is currently open for writing + // by another process (likely Git itself.) + } } }