diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs index 2bdfef2b5153ad..d2c189d1767d9d 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs @@ -15,10 +15,13 @@ internal sealed class SimpleConsoleFormatter : ConsoleFormatter, IDisposable private const string LoglevelPadding = ": "; private static readonly string _messagePadding = new string(' ', GetLogLevelString(LogLevel.Information).Length + LoglevelPadding.Length); private static readonly string _newLineWithMessagePadding = Environment.NewLine + _messagePadding; - private static readonly bool _isAndroidOrAppleMobile = RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")) - || RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")) - || RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")) - || RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST")); +#if NETCOREAPP + private static bool IsAndroidOrAppleMobile => OperatingSystem.IsAndroid() || + OperatingSystem.IsTvOS() || + OperatingSystem.IsIOS(); // returns true on MacCatalyst +#else + private static bool IsAndroidOrAppleMobile => false; +#endif private IDisposable? _optionsReloadToken; public SimpleConsoleFormatter(IOptionsMonitor options) @@ -165,7 +168,7 @@ private ConsoleColors GetLogLevelConsoleColors(LogLevel logLevel) // We shouldn't be outputting color codes for Android/Apple mobile platforms, // they have no shell (adb shell is not meant for running apps) and all the output gets redirected to some log file. bool disableColors = (FormatterOptions.ColorBehavior == LoggerColorBehavior.Disabled) || - (FormatterOptions.ColorBehavior == LoggerColorBehavior.Default && (!ConsoleUtils.EmitAnsiColorCodes || _isAndroidOrAppleMobile)); + (FormatterOptions.ColorBehavior == LoggerColorBehavior.Default && (!ConsoleUtils.EmitAnsiColorCodes || IsAndroidOrAppleMobile)); if (disableColors) { return new ConsoleColors(null, null);