[英]Set Linux and Windows path in .NET/c# to create a log file
I am trying to set a unified path for my .NET application. 我正在尝试为.NET应用程序设置统一路径。
Currently the path is hard coded for Windows. 当前,该路径是针对Windows的硬编码。 It looks like this:
看起来像这样:
var tempFilename = $@"C:\Logs\{ApplicationName}\RollingFile.log";
How can I create the path where it handles both linux and windows? 如何在处理Linux和Windows的地方创建路径?
Use a special path like LB said. 使用像LB这样的特殊路径。 Or run a check to see if you are running on linux.
或运行检查以查看您是否在Linux上运行。
int platformInt = (int)Environment.OSVersion.Platform;
if((p == 4) || (p == 6) || (p == 128))
{
var tempFilename = $@"linuxpath";
}
This will detect if the computer is running Linux. 这将检测计算机是否正在运行Linux。 Look here for more.
在这里查看更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.