【问题标题】:Set Linux and Windows path in .NET/c# to create a log file在 .NET/c# 中设置 Linux 和 Windows 路径以创建日志文件
【发布时间】:2018-01-20 13:19:47
【问题描述】:

我正在尝试为我的 .NET 应用程序设置统一路径。

目前该路径是针对 Windows 进行硬编码的。它看起来像这样:

var tempFilename = $@"C:\Logs\{ApplicationName}\RollingFile.log";

如何创建同时处理 linux 和 windows 的路径?

【问题讨论】:

  • 也许Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

标签: c# .net linux path


【解决方案1】:

使用 L.B 所说的特殊路径。或者运行检查以查看您是否在 linux 上运行。

int platformInt = (int)Environment.OSVersion.Platform;
if((p == 4) || (p == 6) || (p == 128))
{
    var tempFilename = $@"linuxpath"; 
}

这将检测计算机是否运行 Linux。更多信息请关注here

【讨论】:

    猜你喜欢
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多