我正在尝试为我的 .NET 应用程序设置一个统一的路径。
目前路径是针对 Windows 的硬编码。它看起来像这样:
var tempFilename = $@"C:\Logs\{ApplicationName}\RollingFile.log";
如何创建同时处理 linux 和 windows 的路径?
最佳答案
像L.B说的那样使用特殊路径。或者运行检查以查看您是否在 linux 上运行。
int platformInt = (int)Environment.OSVersion.Platform;
if((p == 4) || (p == 6) || (p == 128))
{
var tempFilename = $@"linuxpath";
}
这将检测计算机是否正在运行 Linux。看here了解更多。
关于c# - 在 .NET/c# 中设置 Linux 和 Windows 路径以创建日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45645094/