Skip to content

Instantly share code, notes, and snippets.

@solrevdev
Last active January 4, 2018 09:40
Show Gist options
  • Save solrevdev/ecc2c13f2fa9476a8328a3074e714988 to your computer and use it in GitHub Desktop.
Save solrevdev/ecc2c13f2fa9476a8328a3074e714988 to your computer and use it in GitHub Desktop.
Class to help your code know if you are running on windows or mac/mono
public static class PlatformHelper
{
static readonly Lazy<bool> IsRunningOnMonoValue = new Lazy<bool>(() =>
{
return Type.GetType("Mono.Runtime") != null;
});
public static bool IsRunningOnMono()
{
return IsRunningOnMonoValue.Value;
}
public static void SetLogFactoryBasedOnPlatform()
{
var isMono = PlatformHelper.IsRunningOnMono();
if (isMono)
LogManager.LogFactory = new ConsoleLogFactory();
else
LogManager.LogFactory = new NLogFactory();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment