Created
February 27, 2018 07:55
-
-
Save richlander/539442f699f7f45818ebe5839c66d17d to your computer and use it in GitHub Desktop.
Using Registry APIs with .NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GetLoggingPath() | |
{ | |
// Verify the code is running on Windows. | |
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | |
{ | |
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Fabrikam\AssetManagement")) | |
{ | |
if (key?.GetValue("LoggingDirectoryPath") is string configuredPath) | |
return configuredPath; | |
} | |
} | |
// This is either not running on Windows or no logging path was configured, | |
// so just use the path for non-roaming user-specific data files. | |
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | |
return Path.Combine(appDataPath, "Fabrikam", "AssetManagement", "Logging"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/