简体   繁体   中英

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.

Currently the path is hard coded for 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?

Use a special path like LB said. Or run a check to see if you are running on 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. Look here for more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM