Last active
January 4, 2018 09:40
-
-
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
This file contains hidden or 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
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