Skip to content

Instantly share code, notes, and snippets.

@richlander
Created February 27, 2018 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlander/539442f699f7f45818ebe5839c66d17d to your computer and use it in GitHub Desktop.
Save richlander/539442f699f7f45818ebe5839c66d17d to your computer and use it in GitHub Desktop.
Using Registry APIs with .NET Core
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