轉自:https://www.cnblogs.com/51net/p/12172436.html
Windows和Linux路徑分隔符不一樣
C#開發語言中的路徑分隔符為:Path.DirectorySeparatorChar
測試:
public ActionResult<object> PathTest() { var baseDirectory = AppContext.BaseDirectory; var customDirectory = Path.Combine(baseDirectory, "xxx\\trace.log"); var customDirectory2 = Path.Combine(baseDirectory, "\\xxx\\trace.log"); var customDirectoryReplaced = customDirectory.Replace('\\', Path.DirectorySeparatorChar); return new { baseDirectory, customDirectory, customDirectory2, customDirectoryReplaced, Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar, Path.PathSeparator, Path.VolumeSeparatorChar }; }
