Skip to content

Commit

Permalink
Only use fancy colors in Windows 10 / Server 2016+
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterTinus committed Jan 17, 2020
1 parent f666e70 commit 3bcf2aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main.lib/Services/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace PKISharp.WACS.Services
{
Expand All @@ -32,17 +33,27 @@ public LogService()
_levelSwitch = new LoggingLevelSwitch(initialMinimumLevel: initialLevel);
try
{
var theme =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.Major == 10 ?
(ConsoleTheme)AnsiConsoleTheme.Code :
SystemConsoleTheme.Literate;

_screenLogger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(_levelSwitch)
.Enrich.FromLogContext()
.Filter.ByIncludingOnly(x => { Dirty = true; return true; })
.WriteTo.Console(outputTemplate: " {Message:l}{NewLine}", theme: AnsiConsoleTheme.Code)
.WriteTo.Console(
outputTemplate: " {Message:l}{NewLine}",
theme: theme)
.CreateLogger();
_debugScreenLogger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(_levelSwitch)
.Enrich.FromLogContext()
.Filter.ByIncludingOnly(x => { Dirty = true; return true; })
.WriteTo.Console(outputTemplate: " [{Level:u4}] {Message:l}{NewLine}{Exception}", theme: AnsiConsoleTheme.Code)
.WriteTo.Console(
outputTemplate: " [{Level:u4}] {Message:l}{NewLine}{Exception}",
theme: theme)
.CreateLogger();
}
catch (Exception ex)
Expand Down
12 changes: 12 additions & 0 deletions src/main/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
1 change: 1 addition & 0 deletions src/main/wacs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Version>2.1.2.0</Version>
<AssemblyVersion>2.1.2.0</AssemblyVersion>
<FileVersion>2.1.2.0</FileVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 3bcf2aa

Please sign in to comment.