Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
fix: remove invalid file name characters
Browse files Browse the repository at this point in the history
  • Loading branch information
cruikshj committed Aug 11, 2016
1 parent 0edf921 commit 3a50684
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions SMLogging/FileTraceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ private string FormatFilePath(string path)
namedArgs["DateTime"] = dateTime;
namedArgs["Timestamp"] = DateTime.UtcNow.Ticks;
namedArgs["ProcessId"] = _processId;
namedArgs["ProcessName"] = _processName;
namedArgs["AppName"] = _appName;
namedArgs["ProcessName"] = RemoveInvalidFileNameCharacters(_processName);
namedArgs["AppName"] = RemoveInvalidFileNameCharacters(_appName);

return StringHelpers.NamedFormat(CultureInfo.InvariantCulture, path, namedArgs);
}
Expand Down Expand Up @@ -648,6 +648,16 @@ private FileLockHandlerBase CreateLockHandler()
}
}

private static string RemoveInvalidFileNameCharacters(string value)
{
foreach (var invalidChar in Path.GetInvalidFileNameChars())
{
value = value.Replace(invalidChar.ToString(), string.Empty);
}

return value;
}

#endregion

#region Private Fields
Expand Down

0 comments on commit 3a50684

Please sign in to comment.