|
17 | 17 | using System.Diagnostics.CodeAnalysis; |
18 | 18 | using System.IO; |
19 | 19 | using System.Net; |
| 20 | +using System.Runtime.InteropServices; |
20 | 21 | using System.Threading; |
21 | 22 | using System.Threading.Tasks; |
22 | 23 | using Autofac; |
|
36 | 37 | using Serilog.Events; |
37 | 38 | using Serilog.Formatting.Compact; |
38 | 39 |
|
39 | | -#if WINDOWS |
40 | 40 | using System.Security.Cryptography.X509Certificates; |
41 | 41 | using SeqCli.Forwarder.ServiceProcess; |
42 | | -#endif |
43 | 42 |
|
44 | 43 | // ReSharper disable UnusedType.Global |
45 | 44 |
|
@@ -134,12 +133,16 @@ protected override async Task<int> Run(string[] unrecognized) |
134 | 133 | { |
135 | 134 | options.Listen(ipAddress, apiListenUri.Port, listenOptions => |
136 | 135 | { |
137 | | -#if WINDOWS |
138 | | - listenOptions.UseHttps(StoreName.My, apiListenUri.Host, |
139 | | - location: StoreLocation.LocalMachine, allowInvalid: true); |
140 | | -#else |
141 | | - listenOptions.UseHttps(); |
142 | | -#endif |
| 136 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 137 | + { |
| 138 | + listenOptions.UseHttps(StoreName.My, apiListenUri.Host, |
| 139 | + location: StoreLocation.LocalMachine, allowInvalid: true); |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + listenOptions.UseHttps(); |
| 144 | + } |
| 145 | + |
143 | 146 | }); |
144 | 147 | } |
145 | 148 | else |
@@ -193,14 +196,14 @@ protected override async Task<int> Run(string[] unrecognized) |
193 | 196 | // ReSharper disable once UnusedParameter.Local |
194 | 197 | static int RunService(ServerService service) |
195 | 198 | { |
196 | | -#if WINDOWS |
197 | | - System.ServiceProcess.ServiceBase.Run([ |
198 | | - new SeqCliForwarderWindowsService(service) |
199 | | - ]); |
200 | | - return 0; |
201 | | -#else |
202 | | - throw new NotSupportedException("Windows services are not supported on this platform."); |
203 | | -#endif |
| 199 | + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 200 | + throw new NotSupportedException("Windows services are not supported on this platform."); |
| 201 | + |
| 202 | + |
| 203 | + System.ServiceProcess.ServiceBase.Run([ |
| 204 | + new SeqCliForwarderWindowsService(service) |
| 205 | + ]); |
| 206 | + return 0; |
204 | 207 | } |
205 | 208 |
|
206 | 209 | static async Task<int> RunStandardIOAsync(ServerService service, TextWriter cout) |
|
0 commit comments