|
4 | 4 | using System;
|
5 | 5 | using System.Diagnostics.CodeAnalysis;
|
6 | 6 | using System.Runtime.CompilerServices;
|
| 7 | +using System.Runtime.InteropServices; |
| 8 | +using System.Runtime.Versioning; |
7 | 9 | using System.Xml.Linq;
|
8 | 10 | using Microsoft.AspNetCore.DataProtection;
|
9 | 11 | using Microsoft.Win32;
|
@@ -95,7 +97,7 @@ internal static class LoggingExtensions
|
95 | 97 |
|
96 | 98 | private static Action<ILogger, string, Exception?> _writingDataToFile;
|
97 | 99 |
|
98 |
| - private static Action<ILogger, RegistryKey, string, Exception?> _readingDataFromRegistryKeyValue; |
| 100 | + private static Action<ILogger, RegistryKey, string, Exception?>? _readingDataFromRegistryKeyValue; |
99 | 101 |
|
100 | 102 | private static Action<ILogger, string, string, Exception?> _nameIsNotSafeRegistryValueName;
|
101 | 103 |
|
@@ -305,10 +307,15 @@ static LoggingExtensions()
|
305 | 307 | eventId: new EventId(39, "WritingDataToFile"),
|
306 | 308 | logLevel: LogLevel.Information,
|
307 | 309 | formatString: "Writing data to file '{FileName}'.");
|
308 |
| - _readingDataFromRegistryKeyValue = LoggerMessage.Define<RegistryKey, string>( |
309 |
| - eventId: new EventId(40, "ReadingDataFromRegistryKeyValue"), |
310 |
| - logLevel: LogLevel.Debug, |
311 |
| - formatString: "Reading data from registry key '{RegistryKeyName}', value '{Value}'."); |
| 310 | + |
| 311 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 312 | + { |
| 313 | + _readingDataFromRegistryKeyValue = LoggerMessage.Define<RegistryKey, string>( |
| 314 | + eventId: new EventId(40, "ReadingDataFromRegistryKeyValue"), |
| 315 | + logLevel: LogLevel.Debug, |
| 316 | + formatString: "Reading data from registry key '{RegistryKeyName}', value '{Value}'."); |
| 317 | + } |
| 318 | + |
312 | 319 | _nameIsNotSafeRegistryValueName = LoggerMessage.Define<string, string>(
|
313 | 320 | eventId: new EventId(41, "NameIsNotSafeRegistryValueName"),
|
314 | 321 | logLevel: LogLevel.Debug,
|
@@ -662,9 +669,13 @@ public static void WritingDataToFile(this ILogger logger, string finalFilename)
|
662 | 669 | _writingDataToFile(logger, finalFilename, null);
|
663 | 670 | }
|
664 | 671 |
|
| 672 | + [SupportedOSPlatform("windows")] |
665 | 673 | public static void ReadingDataFromRegistryKeyValue(this ILogger logger, RegistryKey regKey, string valueName)
|
666 | 674 | {
|
667 |
| - _readingDataFromRegistryKeyValue(logger, regKey, valueName, null); |
| 675 | + if (_readingDataFromRegistryKeyValue != null) |
| 676 | + { |
| 677 | + _readingDataFromRegistryKeyValue(logger, regKey, valueName, null); |
| 678 | + } |
668 | 679 | }
|
669 | 680 |
|
670 | 681 | public static void NameIsNotSafeRegistryValueName(this ILogger logger, string friendlyName, string newFriendlyName)
|
|
0 commit comments