转自: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 }; }