diff --git a/Yubico.Core/src/Yubico.Core.csproj b/Yubico.Core/src/Yubico.Core.csproj
index 55f20805..b91cfdcd 100644
--- a/Yubico.Core/src/Yubico.Core.csproj
+++ b/Yubico.Core/src/Yubico.Core.csproj
@@ -107,7 +107,10 @@ limitations under the License. -->
-
+
+
+
+
diff --git a/Yubico.Core/src/Yubico/Core/Buffers/Hex.cs b/Yubico.Core/src/Yubico/Core/Buffers/Hex.cs
index 3767e855..dd6a9cb6 100644
--- a/Yubico.Core/src/Yubico/Core/Buffers/Hex.cs
+++ b/Yubico.Core/src/Yubico/Core/Buffers/Hex.cs
@@ -19,8 +19,6 @@ namespace Yubico.Core.Buffers
///
///
/// This class is an alias for . New code should use that class
- /// and existing code should be changed over time. Putting the
- /// on this class is impractical.
///
public class Hex : Base16
{
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/HidDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/HidDeviceListener.cs
index 08330308..4c7035da 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/HidDeviceListener.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/HidDeviceListener.cs
@@ -13,7 +13,7 @@
// limitations under the License.
using System;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.Hid
@@ -35,7 +35,7 @@ namespace Yubico.Core.Devices.Hid
///
public abstract class HidDeviceListener
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
///
/// Subscribe to receive an event whenever a Human Interface Device (HID) is added to the computer.
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/HidLoggerExtensions.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/HidLoggerExtensions.cs
index d98bbcef..f7ff413b 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/HidLoggerExtensions.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/HidLoggerExtensions.cs
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.Hid
{
internal static class HidLoggerExtensions
{
- public static void IOKitApiCall(this Logger logger, string apiName, kern_return_t result)
+ public static void IOKitApiCall(this ILogger logger, string apiName, kern_return_t result)
{
if (result == kern_return_t.KERN_SUCCESS)
{
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidDevice.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidDevice.cs
index 5ddbe2d9..11c55c77 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidDevice.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidDevice.cs
@@ -15,7 +15,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.Hid
@@ -34,7 +34,7 @@ internal class LinuxHidDevice : HidDevice
private readonly string _devnode;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
///
/// Gets a list of all the HIDs on the system (not just YubiKeys).
@@ -78,7 +78,7 @@ internal LinuxHidDevice(string path, string devnode, string? parentPath) :
if (handle.IsInvalid)
{
_log.LogWarning(
- "Could not open [{Path}]. Errno = {errno} {errorstring}",
+ "Could not open [{Path}]. Errno = {ErrNo} {ErrorString}",
path, Marshal.GetLastWin32Error(), LibcHelpers.GetErrnoString());
}
@@ -136,7 +136,7 @@ private void GetVendorProductIds(LinuxFileSafeHandle handle)
}
else
{
- _log.LogWarning("IOCTL failed. {error}", LibcHelpers.GetErrnoString());
+ _log.LogWarning("IOCTL failed. {Error}", LibcHelpers.GetErrnoString());
}
Marshal.FreeHGlobal(infoStructData);
@@ -161,7 +161,7 @@ private void GetUsageProperties(LinuxFileSafeHandle handle)
}
else
{
- _log.LogWarning("IOCTL failed. {error}", LibcHelpers.GetErrnoString());
+ _log.LogWarning("IOCTL failed. {Error}", LibcHelpers.GetErrnoString());
}
Marshal.FreeHGlobal(descriptorStructData);
}
@@ -178,7 +178,7 @@ private static int GetDescriptorLength(LinuxFileSafeHandle handle)
}
else
{
- Log.GetLogger().LogWarning("IOCTL failed. {error}", LibcHelpers.GetErrnoString());
+ Logging.Log.GetLogger(typeof(LinuxHidDevice).FullName!).LogWarning("IOCTL failed. {Error}", LibcHelpers.GetErrnoString());
}
Marshal.FreeHGlobal(descSize);
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidIOReportConnection.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidIOReportConnection.cs
index c9c7eb16..0c21c45a 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidIOReportConnection.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/LinuxHidIOReportConnection.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Buffers;
using Yubico.Core.Logging;
using Yubico.PlatformInterop;
@@ -28,7 +29,7 @@ internal class LinuxHidIOReportConnection : IHidConnection
private readonly LinuxFileSafeHandle _handle;
private bool _isDisposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
private readonly LinuxHidDevice _device;
public int InputReportSize { get; private set; }
@@ -46,7 +47,7 @@ public LinuxHidIOReportConnection(LinuxHidDevice device, string devnode)
if (_handle.IsInvalid)
{
- _log.LogError("Could not open device for IO reports: {error}", LibcHelpers.GetErrnoString());
+ _log.LogError("Could not open device for IO reports: {Error}", LibcHelpers.GetErrnoString());
throw new PlatformApiException(
string.Format(
@@ -84,7 +85,7 @@ public void SetReport(byte[] report)
return;
}
- _log.LogError("Write failed with: {error}", LibcHelpers.GetErrnoString());
+ _log.LogError("Write failed with: {Error}", LibcHelpers.GetErrnoString());
throw new PlatformApiException(
string.Format(
@@ -108,7 +109,7 @@ public byte[] GetReport()
return outputBuffer;
}
- _log.LogError("Read failed with: {error}", LibcHelpers.GetErrnoString());
+ _log.LogError("Read failed with: {Error}", LibcHelpers.GetErrnoString());
throw new PlatformApiException(
string.Format(
CultureInfo.CurrentCulture,
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs
index 260c3d9a..27a6ca09 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs
@@ -16,20 +16,21 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
+using Yubico.Core.Logging;
using static Yubico.PlatformInterop.NativeMethods;
namespace Yubico.Core.Devices.Hid
{
///
- /// macOS implementation of a Human Interface Device (HID)
+ /// MacOS implementation of a Human Interface Device (HID)
///
internal class MacOSHidDevice : HidDevice
{
private readonly long _entryId;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
public MacOSHidDevice(long entryId) :
base(entryId.ToString(CultureInfo.InvariantCulture))
@@ -49,7 +50,7 @@ public MacOSHidDevice(long entryId) :
///
public static IEnumerable GetList()
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(MacOSHidDevice).FullName!);
using IDisposable? logScope = log.BeginScope("MacOSHidDevice.GetList()");
IntPtr manager = IntPtr.Zero;
@@ -116,7 +117,7 @@ public override IHidConnection ConnectToIOReports() =>
internal static long GetEntryId(IntPtr device)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(MacOSHidDevice).FullName!);
int service = IOHIDDeviceGetService(device);
kern_return_t result = IORegistryEntryGetRegistryEntryID(service, out long entryId);
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDeviceListener.cs
index 6f0b9578..92611f26 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDeviceListener.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDeviceListener.cs
@@ -15,7 +15,7 @@
using System;
using System.Text;
using System.Threading;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using static Yubico.PlatformInterop.NativeMethods;
namespace Yubico.Core.Devices.Hid
@@ -28,7 +28,7 @@ internal class MacOSHidDeviceListener : HidDeviceListener
private Thread? _listenerThread;
private IntPtr? _runLoop;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
// Start listening as soon as this object is constructed.
public MacOSHidDeviceListener()
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidFeatureReportConnection.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidFeatureReportConnection.cs
index d888b841..8caf57d5 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidFeatureReportConnection.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidFeatureReportConnection.cs
@@ -13,6 +13,7 @@
// limitations under the License.
using System;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Buffers;
using Yubico.Core.Logging;
using Yubico.PlatformInterop;
@@ -28,7 +29,7 @@ internal sealed class MacOSHidFeatureReportConnection : IHidConnection
private readonly MacOSHidDevice _device;
private readonly long _entryId;
private IntPtr _deviceHandle;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
private bool _isDisposed;
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidIOReportConnection.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidIOReportConnection.cs
index 2c068045..b91faffd 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidIOReportConnection.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidIOReportConnection.cs
@@ -17,6 +17,7 @@
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Buffers;
using Yubico.Core.Logging;
using Yubico.PlatformInterop;
@@ -34,7 +35,7 @@ internal sealed class MacOSHidIOReportConnection : IHidConnection
private bool _isDisposed;
private readonly MacOSHidDevice _device;
private readonly IntPtr _loopId;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
private readonly byte[] _readBuffer;
private GCHandle _readHandle;
@@ -246,14 +247,14 @@ private static void ReportCallback(
byte[] report,
long reportLength)
{
- Logger log = Log.GetLogger();
+ ILogger logger = Logging.Log.GetLogger(typeof(MacOSHidIOReportConnection).FullName!);
- log.LogInformation("MacOSHidIOReportConnection.ReportCallback has been called.");
+ logger.LogInformation("MacOSHidIOReportConnection.ReportCallback has been called.");
if (result != 0 || type != IOKitHidConstants.kIOHidReportTypeInput || reportId != 0 || reportLength < 0)
{
// Something went wrong. We don't currently signal, just continue.
- log.LogWarning(
+ logger.LogWarning(
"ReportCallback did not receive some or all of the expected output.\n" +
"result = [{Result}], type = [{Type}], reportId = [{ReportId}], reportLength = [{ReportLength}]",
result,
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs
index 38e7514c..315ee0da 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs
@@ -17,7 +17,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.Hid
@@ -27,7 +27,7 @@ namespace Yubico.Core.Devices.Hid
///
internal class WindowsHidDevice : HidDevice
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
///
/// Gets the list of Windows HID devices available to the system.
diff --git a/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDeviceListener.cs
index 556bdd8b..728f0aa7 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDeviceListener.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDeviceListener.cs
@@ -16,7 +16,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
using static Yubico.PlatformInterop.NativeMethods;
@@ -29,7 +29,7 @@ internal class WindowsHidDeviceListener : HidDeviceListener
private GCHandle? _marshalableThisPtr;
private CM_NOTIFY_CALLBACK? _callbackDelegate;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
public WindowsHidDeviceListener()
{
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardConnection.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardConnection.cs
index a8b6aaf8..cfd30ac6 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardConnection.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardConnection.cs
@@ -13,8 +13,8 @@
// limitations under the License.
using System;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
-using Yubico.Core.Logging;
using Yubico.PlatformInterop;
using static Yubico.PlatformInterop.NativeMethods;
@@ -23,7 +23,7 @@ namespace Yubico.Core.Devices.SmartCard
{
public class DesktopSmartCardConnection : ISmartCardConnection
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
private readonly DesktopSmartCardDevice _device;
private readonly SCardContext _context;
private readonly SCardCardHandle _cardHandle;
@@ -31,7 +31,7 @@ public class DesktopSmartCardConnection : ISmartCardConnection
private class TransactionScope : IDisposable
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
private readonly DesktopSmartCardConnection _thisConnection;
private readonly IDisposable? _logScope;
private bool _disposedValue;
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDevice.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDevice.cs
index d0a50c26..a27362c0 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDevice.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDevice.cs
@@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.PlatformInterop;
@@ -27,11 +28,11 @@ namespace Yubico.Core.Devices.SmartCard
internal class DesktopSmartCardDevice : SmartCardDevice
{
private readonly string _readerName;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
public static IReadOnlyList GetList()
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger();
using IDisposable? logScope = log.BeginScope("SmartCardDevice.GetList()");
uint result = SCardEstablishContext(SCARD_SCOPE.USER, out SCardContext context);
@@ -112,7 +113,6 @@ public DesktopSmartCardDevice(string readerName, AnswerToReset? atr) :
base(readerName, atr)
{
_readerName = readerName;
- _log = Log.GetLogger();
}
public override ISmartCardConnection Connect()
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs
index a8c95e27..c80822ab 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/DesktopSmartCardDeviceListener.cs
@@ -17,7 +17,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
using static Yubico.PlatformInterop.NativeMethods;
@@ -29,7 +29,7 @@ namespace Yubico.Core.Devices.SmartCard
///
internal class DesktopSmartCardDeviceListener : SmartCardDeviceListener, IDisposable
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
// The resource manager context.
private SCardContext _context;
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDevice.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDevice.cs
index 20592a8a..231b6a34 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDevice.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDevice.cs
@@ -14,8 +14,8 @@
using System;
using System.Collections.Generic;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
-using Yubico.Core.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.SmartCard
@@ -25,7 +25,7 @@ namespace Yubico.Core.Devices.SmartCard
///
public abstract class SmartCardDevice : ISmartCardDevice
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
///
public DateTime LastAccessed { get; protected set; } = DateTime.MinValue;
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDeviceListener.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDeviceListener.cs
index 996dde36..a2266bee 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDeviceListener.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardDeviceListener.cs
@@ -13,7 +13,7 @@
// limitations under the License.
using System;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.SmartCard
@@ -35,7 +35,7 @@ namespace Yubico.Core.Devices.SmartCard
///
public abstract class SmartCardDeviceListener
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Logging.Log.GetLogger();
///
/// Subscribe to receive an event whenever a smart card device is added to the computer.
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs
new file mode 100644
index 00000000..d1290c32
--- /dev/null
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs
@@ -0,0 +1,29 @@
+using System;
+using Yubico.Core.Logging;
+using Yubico.PlatformInterop;
+namespace Yubico.Core.Devices.SmartCard
+{
+ internal static partial class SmartCardLoggerExtensions
+ {
+ [Obsolete("Obsolete")]
+ public static IDisposable BeginTransactionScope(this Logger logger, IDisposable transactionScope) =>
+ logger.BeginScope("Transaction[{TransactionID}]", transactionScope.GetHashCode())!;
+
+ [Obsolete("Obsolete")]
+ public static void SCardApiCall(this Logger logger, string apiName, uint result)
+ {
+ if (result == ErrorCode.SCARD_S_SUCCESS)
+ {
+ logger.LogInformation("{APIName} called successfully.", apiName);
+ }
+ else
+ {
+ logger.LogError("{APIName} called and FAILED. Result = {Result}", apiName, result);
+ }
+ }
+
+ [Obsolete("Obsolete, use the corresponding ILogger")]
+ public static void CardReset(this Logger logger) =>
+ logger.LogWarning("The smart card was reset.");
+ }
+}
diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.cs
index f6224383..2a893b8e 100644
--- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.cs
+++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.cs
@@ -1,17 +1,17 @@
// Copyright (c) Yubico AB
using System;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.PlatformInterop;
namespace Yubico.Core.Devices.SmartCard
{
- internal static class SmartCardLoggerExtensions
+ internal static partial class SmartCardLoggerExtensions
{
- public static IDisposable? BeginTransactionScope(this Logger logger, IDisposable transactionScope) =>
+ public static IDisposable? BeginTransactionScope(this ILogger logger, IDisposable transactionScope) =>
logger.BeginScope("Transaction[{TransactionID}]", transactionScope.GetHashCode());
- public static void SCardApiCall(this Logger logger, string apiName, uint result)
+ public static void SCardApiCall(this ILogger logger, string apiName, uint result)
{
if (result == ErrorCode.SCARD_S_SUCCESS)
{
@@ -27,7 +27,7 @@ public static void SCardApiCall(this Logger logger, string apiName, uint result)
}
}
- public static void CardReset(this Logger logger) =>
+ public static void CardReset(this ILogger logger) =>
logger.LogWarning("The smart card was reset.");
}
}
diff --git a/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs b/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs
new file mode 100644
index 00000000..b4d78aa8
--- /dev/null
+++ b/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs
@@ -0,0 +1,170 @@
+// Copyright 2021 Yubico AB
+//
+// Licensed under the Apache License, Version 2.0 (the "License").
+// You may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
+
+namespace Yubico.Core.Logging
+{
+ ///
+ /// A static class for managing Yubico SDK logging for this process.
+ ///
+ ///
+ ///
+ /// This class is used for managing the active logger used globally by .NET-based Yubico SDKs in the current process.
+ /// Changing the settings in this class will not have any effect on applications or services that are not running
+ /// within the current application's process. It will affect all libraries contained within - for example, changing
+ /// the logger factory here will impact both the Yubico.YubiKey and Yubico.Core libraries.
+ ///
+ ///
+ /// The property is used to set and control the concrete log to be used by the SDK. By
+ /// default, we send logs to the "null" logger - effectively disabling logging. If you set this property with your
+ /// own logger factory, the SDK will use this log from the point of the set until someone calls this set method again.
+ ///
+ ///
+ /// should be used to return an instance of the class. This is the object
+ /// used to actually write the log messages. It is generally OK to cache an instance of a logger within another
+ /// class instance. Holding a Logger instance open longer than that is not recommended, as changes to the LoggerFactory
+ /// will not be reflected until you call the `GetLogger` method again.
+ ///
+ ///
+ public static partial class Log
+ {
+ private static ILoggerFactory? _factory;
+
+ ///
+ /// The logger factory implementation that should be used by the SDK. Use this to set the active logger.
+ ///
+ ///
+ ///
+ /// The LoggerFactory controls how the concrete log(s) that the SDK will use get created. This is something that
+ /// should be controlled by the application using the SDK, and not the SDK itself. The application can decide
+ /// whether they would like to send events to the Windows Event Log, or to a cross platform logger such as NLog,
+ /// Serilog, or others. An application can decide to send log messages to multiple sinks as well (see examples).
+ ///
+ ///
+ /// The interface is the same one that is used by `Microsoft.Extensions.Logging.` You
+ /// can read more about how to integrate with this interface in the
+ /// [Logging in .NET](https://docs.microsoft.com/en-us/dotnet/core/extensions/logging) webpage provided by Microsoft.
+ ///
+ ///
+ ///
+ ///
+ /// Send SDK log messages to the console:
+ ///
+ ///
+ /// using Microsoft.Extensions.Logging;
+ /// using Yubico.Core.Logging;
+ ///
+ /// static class Program
+ /// {
+ /// static void EnableLogging()
+ /// {
+ /// Log.LoggerFactory = LoggerFactory.Create(
+ /// builder => builder.AddSimpleConsole(
+ /// options =>
+ /// {
+ /// options.IncludeScopes = true;
+ /// options.SingleLine = true;
+ /// options.TimestampFormat = "hh:mm:ss";
+ /// })
+ /// .AddFilter(level => level >= LogLevel.Information));
+ /// }
+ /// }
+ ///
+ ///
+ ///
+ ///
+ /// Send SDK log messages to Serilog.
+ ///
+ ///
+ /// First, begin by adding a package reference to `Serilog.Extensions.Logging` and `Serilog.Sinks.Console` (or
+ /// to the appropriate sink you plan to use).
+ ///
+ ///
+ /// Now, you can add the following code to your application:
+ ///
+ ///
+ /// using Microsoft.Extensions.Logging;
+ /// using Serilog;
+ /// using Yubico.Core.Logging;
+ ///
+ /// static class Program
+ /// {
+ /// static void EnableLogging()
+ /// {
+ /// // Serilog does setup through its own LoggerConfiguration builder. The factory will
+ /// // pick up the log from Serilog.Log.Logger.
+ /// Serilog.Log.Logger = new LoggerConfiguration()
+ /// .Enrich().FromLogContext()
+ /// .WriteTo.Console()
+ /// .CreateLogger();
+ ///
+ /// // Fully qualified name to avoid conflicts with Serilog types
+ /// Yubico.Core.Logging.Log.LoggerFactory = LoggerFactory.Create(
+ /// builder => builder
+ /// .AddSerilog(dispose: true)
+ /// .AddFilter(level => level >= LogLevel.Information));
+ /// }
+ /// }
+ ///
+ ///
+ [Obsolete("Obsolete, use Log.Instance instead. Setting this will override the default dotnet console logger.")]
+ public static ILoggerFactory LoggerFactory
+ {
+ get => _factory ??= new NullLoggerFactory();
+ set
+ {
+ _factory = value;
+
+ // Also swap out the new implementation instance
+ Instance = value;
+ }
+ }
+
+ ///
+ /// Gets an instance of the active logger.
+ ///
+ ///
+ /// An instance of the active concrete logger.
+ ///
+ ///
+ ///
+ /// Write some information to the log.
+ ///
+ ///
+ /// using Yubico.Core.Logging;
+ ///
+ /// public class Example
+ /// {
+ /// private Logger _log = Log.GetLogger();
+ ///
+ /// public void SampleMethod()
+ /// {
+ /// _log.LogDebug("The SampleMethod method has been called!");
+ /// }
+ ///
+ /// public void StaticMethod()
+ /// {
+ /// Logger log = Log.GetLogger(); // Can't use the instance logger because we're static.
+ /// log.LogDebug("Called from a static method!");
+ /// }
+ /// }
+ ///
+ ///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static Logger GetLogger() => new Logger(Yubico.Core.Logging.Log.LoggerFactory.CreateLogger("Yubico.Core logger"));
+ }
+}
diff --git a/Yubico.Core/src/Yubico/Core/Logging/Log.cs b/Yubico.Core/src/Yubico/Core/Logging/Log.cs
index 1555b822..aa7506d1 100644
--- a/Yubico.Core/src/Yubico/Core/Logging/Log.cs
+++ b/Yubico.Core/src/Yubico/Core/Logging/Log.cs
@@ -12,150 +12,180 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+using System;
+using System.IO;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Logging.Abstractions;
namespace Yubico.Core.Logging
{
///
- /// A static class for managing Yubico SDK logging for this process.
+ /// The class provides centralized logging support for your application or library.
+ /// It allows you to configure logging either through a JSON configuration file (appsettings.json)
+ /// or by dynamically setting up a logger using the method.
+ ///
+ /// How to enable Logging:
+ /// There are two primary ways to enable logging:
+ ///
+ /// - 1. Add an appsettings.json to your project.
+ /// - 2. Use the method.
+ ///
+ ///
+ /// Option 1: Using appsettings.json
+ /// Place an appsettings.json file in your project directory with the following structure:
+ ///
+ /// {
+ /// "Logging": {
+ /// "LogLevel": {
+ /// "Yubico.Core": "Warning",
+ /// "Yubico.Yubikey": "Information"
+ /// }
+ /// }
+ /// }
+ ///
+ ///
+ /// Option 2: Using ConfigureLoggerFactory
+ /// Configure the logger dynamically in your code:
+ ///
+ ///
+ ///
+ /// // Optionally, clear previous loggers
+ /// Log.ConfigureLoggerFactory(builder => builder.ClearProviders());
+ ///
+ /// // Add a console logger (added by default)
+ /// Log.ConfigureLoggerFactory(builder => builder.AddConsole());
+ ///
+ /// // Add a Serilog logger
+ /// Log.ConfigureLoggerFactory(builder => builder.AddSerilog());
+ ///
+ /// // Add both Console and Serilog loggers
+ /// Log.ConfigureLoggerFactory(builder => builder.AddConsole().AddSerilog());
+ ///
+ ///
+ ///
+ /// Using the Logger
+ /// After configuring the logger, you can create log instances and log messages as follows:
+ ///
+ ///
+ /// namespace Yubico;
+ /// public class ExampleClass
+ /// {
+ /// public ExampleClass()
+ /// {
+ /// // Logger with the class name as the category
+ /// ILogger typeNamedLogger = Log.GetLogger<ExampleClass>();
+ /// typeNamedLogger.LogInformation("Hello World");
+ /// // Output: Yubico.ExampleClass: Hello World
+ ///
+ /// // Logger with a custom category name
+ /// ILogger categoryLogger = Log.GetLogger("SmartCard");
+ /// categoryLogger.LogInformation("Hello World");
+ /// // Output: SmartCard: Hello World
+ /// }
+ /// }
+ ///
+ ///
+ ///
+ /// Note:
+ /// You can also directly set a custom logger factory using the property,
+ /// though it is not the recommended approach. Using
+ /// or the appsettings.json approach is preferred.
///
- ///
- ///
- /// This class is used for managing the active logger used globally by .NET-based Yubico SDKs in the current process.
- /// Changing the settings in this class will not have any effect on applications or services that are not running
- /// within the current application's process. It will affect all libraries contained within - for example, changing
- /// the logger factory here will impact both the Yubico.YubiKey and Yubico.Core libraries.
- ///
- ///
- /// The property is used to set and control the concrete log to be used by the SDK. By
- /// default, we send logs to the "null" logger - effectively disabling logging. If you set this property with your
- /// own logger factory, the SDK will use this log from the point of the set until someone calls this set method again.
- ///
- ///
- /// should be used to return an instance of the class. This is the object
- /// used to actually write the log messages. It is generally OK to cache an instance of a logger within another
- /// class instance. Holding a Logger instance open longer than that is not recommended, as changes to the LoggerFactory
- /// will not be reflected until you call the `GetLogger` method again.
- ///
- ///
- public static class Log
+ public static partial class Log
{
- private static ILoggerFactory? _factory;
+ private static ILoggerFactory? _instance;
+ private static readonly object Lock = new object();
///
- /// The logger factory implementation that should be used by the SDK. Use this to set the active logger.
+ /// Gets or sets the global instance used for logging throughout the application.
+ /// By default, it's instantiated by using the Logging-section in your
+ /// appsettings.jsonfile.
+ /// Refer to the class for additional information.
///
- ///
- ///
- /// The LoggerFactory controls how the concrete log(s) that the SDK will use get created. This is something that
- /// should be controlled by the application using the SDK, and not the SDK itself. The application can decide
- /// whether they would like to send events to the Windows Event Log, or to a cross platform logger such as NLog,
- /// Serilog, or others. An application can decide to send log messages to multiple sinks as well (see examples).
- ///
- ///
- /// The interface is the same one that is used by `Microsoft.Extensions.Logging.` You
- /// can read more about how to integrate with this interface in the
- /// [Logging in .NET](https://docs.microsoft.com/en-us/dotnet/core/extensions/logging) webpage provided by Microsoft.
- ///
- ///
- ///
- ///
- /// Send SDK log messages to the console:
- ///
- ///
- /// using Microsoft.Extensions.Logging;
- /// using Yubico.Core.Logging;
- ///
- /// static class Program
- /// {
- /// static void EnableLogging()
- /// {
- /// Log.LoggerFactory = LoggerFactory.Create(
- /// builder => builder.AddSimpleConsole(
- /// options =>
- /// {
- /// options.IncludeScopes = true;
- /// options.SingleLine = true;
- /// options.TimestampFormat = "hh:mm:ss";
- /// })
- /// .AddFilter(level => level >= LogLevel.Information));
- /// }
- /// }
- ///
- ///
- ///
- ///
- /// Send SDK log messages to Serilog.
- ///
- ///
- /// First, begin by adding a package reference to `Serilog.Extensions.Logging` and `Serilog.Sinks.Console` (or
- /// to the appropriate sink you plan to use).
- ///
- ///
- /// Now, you can add the following code to your application:
- ///
- ///
- /// using Microsoft.Extensions.Logging;
- /// using Serilog;
- /// using Yubico.Core.Logging;
- ///
- /// static class Program
- /// {
- /// static void EnableLogging()
- /// {
- /// // Serilog does setup through its own LoggerConfiguration builder. The factory will
- /// // pick up the log from Serilog.Log.Logger.
- /// Serilog.Log.Logger = new LoggerConfiguration()
- /// .Enrich().FromLogContext()
- /// .WriteTo.Console()
- /// .CreateLogger();
- ///
- /// // Fully qualified name to avoid conflicts with Serilog types
- /// Yubico.Core.Logging.Log.LoggerFactory = LoggerFactory.Create(
- /// builder => builder
- /// .AddSerilog(dispose: true)
- /// .AddFilter(level => level >= LogLevel.Information));
- /// }
- /// }
- ///
- ///
- public static ILoggerFactory LoggerFactory
+ // This property uses double-checked locking to ensure thread-safe lazy initialization.
+ // The getter initializes the factory if it hasn't been set, while the setter allows
+ // for custom factory configuration.
+ public static ILoggerFactory Instance
{
- get => _factory ??= new NullLoggerFactory();
- set => _factory = value;
+ get
+ {
+ // First check: Quick return if instance is already initialized
+ if (_instance != null)
+ {
+ return _instance;
+ }
+
+ // Second check: Thread-safe initialization if instance is null
+ lock (Lock)
+ {
+ // Use null-coalescing assignment to initialize if still null
+ // This prevents multiple initializations in case of concurrent access
+ return _instance ??= GetDefaultLoggerFactory();
+ }
+ }
+ set
+ {
+ // Ensure thread-safe assignment of new logger factory
+ lock (Lock)
+ {
+ // Prevent setting a null value to maintain a valid logger factory
+ _instance = value ?? throw new ArgumentNullException(nameof(value));
+ }
+ }
}
+ ///
+ public static ILogger GetLogger() => Instance.CreateLogger();
+
+ ///
+ public static ILogger GetLogger(string categoryName) => Instance.CreateLogger(categoryName);
+
///
- /// Gets an instance of the active logger.
- ///
- ///
- /// An instance of the active concrete logger.
- ///
///
- ///
- /// Write some information to the log.
- ///
+ /// From your project, you can set up logging dynamically like this, if you don't use this,
+ /// the default dotnet
+ /// will be created and output to the console.
///
- /// using Yubico.Core.Logging;
- ///
- /// public class Example
- /// {
- /// private Logger _log = Log.GetLogger();
- ///
- /// public void SampleMethod()
- /// {
- /// _log.LogDebug("The SampleMethod method has been called!");
- /// }
- ///
- /// public void StaticMethod()
- /// {
- /// Logger log = Log.GetLogger(); // Can't use the instance logger because we're static.
- /// log.LogDebug("Called from a static method!");
- /// }
- /// }
+ /// Logging.ConfigureLoggerFactory(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Trace));
///
+ /// With the default logging factory, you can load config using json.
///
- public static Logger GetLogger() => new Logger(LoggerFactory.CreateLogger("Yubico.Core logger"));
+ ///
+ ///
+ public static void ConfigureLoggerFactory(Action configure) =>
+ Instance = Microsoft.Extensions.Logging.LoggerFactory.Create(configure);
+
+ //Creates a logging factory based on a JsonConfiguration in appsettings.json
+ private static ILoggerFactory GetDefaultLoggerFactory()
+ {
+ ILoggerFactory? configuredLoggingFactory = null;
+ try
+ {
+ IConfigurationRoot configuration = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: true)
+ .AddJsonFile("appsettings.Development.json", optional: true)
+ .Build();
+
+ configuredLoggingFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(
+ builder =>
+ {
+ IConfigurationSection loggingSection = configuration.GetSection("Logging");
+ _ = builder.AddConfiguration(loggingSection);
+ _ = builder.AddConsole();
+ });
+ }
+#pragma warning disable CA1031
+ catch (Exception e)
+#pragma warning restore CA1031
+ {
+ Console.Error.WriteLine(e);
+ }
+
+ return configuredLoggingFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(
+ builder => builder
+ .AddConsole()
+ .SetMinimumLevel(LogLevel.Error));
+ }
}
}
diff --git a/Yubico.Core/src/Yubico/Core/Logging/Logger.cs b/Yubico.Core/src/Yubico/Core/Logging/Logger.Legacy.cs
similarity index 91%
rename from Yubico.Core/src/Yubico/Core/Logging/Logger.cs
rename to Yubico.Core/src/Yubico/Core/Logging/Logger.Legacy.cs
index 53c110fd..1cedb29a 100644
--- a/Yubico.Core/src/Yubico/Core/Logging/Logger.cs
+++ b/Yubico.Core/src/Yubico/Core/Logging/Logger.Legacy.cs
@@ -1,4 +1,4 @@
-// Copyright 2021 Yubico AB
+// Copyright 2021 Yubico AB
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ namespace Yubico.Core.Logging
/// formatting the error and calling one of the existing log methods.
///
///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
public sealed class Logger : ILogger
{
private readonly ILogger _logger;
@@ -47,6 +48,7 @@ public sealed class Logger : ILogger
/// An instance of the concrete logging mechanism. This should be constructed using the class,
/// and not called directly.
///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
internal Logger(ILogger logger)
{
_logger = logger;
@@ -85,6 +87,7 @@ internal Logger(ILogger logger)
/// a concrete logger with the SDK.
///
///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
public void Log(
LogLevel logLevel,
EventId eventId,
@@ -108,6 +111,7 @@ public void Log(
/// log provider ready to consume it. You can use this method to first test to see if this log level is enabled
/// before running the extra diagnostics code.
///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
///
@@ -122,6 +126,7 @@ public void Log(
///
/// A disposable object that ends the logical operation scope on dispose.
///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
public IDisposable? BeginScope(TState state) where TState : notnull => _logger.BeginScope(state);
}
}
diff --git a/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.Legacy.cs b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.Legacy.cs
new file mode 100644
index 00000000..ce1e551a
--- /dev/null
+++ b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.Legacy.cs
@@ -0,0 +1,1109 @@
+// Copyright 2021 Yubico AB
+//
+// Licensed under the Apache License, Version 2.0 (the "License").
+// You may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using Microsoft.Extensions.Logging;
+
+namespace Yubico.Core.Logging
+{
+ ///
+ /// Logger extension methods for common scenarios.
+ ///
+
+ // These extension methods include both the standard extensions introduced by the Microsoft ILogger APIs, as well
+ // as some new methods for logging potentially sensitive messages. We could have just introduced the sensitive log
+ // methods and re-used the extensions from Microsoft.Extensions.Logging. However, combining them here allows users
+ // of Yubico.Core.Logging to only have to use one namespace (Yubico.Core.Logging), instead of two (Microsoft.Extensions.Logging
+ // as the second). I'm duplicating some code/API/effort in one file to avoid having to over-include in many hundreds
+ // of files. Files that have to include both namespaces should then hopefully be exceptional cases.
+ public static partial class LoggerExtensions
+ {
+ // Needed to satisfy compiling out the sensitive logs in Release builds.
+ // private static void NoOp(params object?[] _) { }
+
+ //------------------------------------------DEBUG------------------------------------------//
+ ///
+ /// Formats and writes a debug log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogDebug(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogDebug(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes a debug log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogDebug(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogDebug(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a debug log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogDebug(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogDebug(eventId, message, args);
+
+ ///
+ /// Formats and writes a debug log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogDebug(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogDebug(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes a debug log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogDebug(this Logger logger, Exception exception, string message, params object?[] args) =>
+ ((ILogger)logger).LogDebug(exception, message, args);
+
+ ///
+ /// Formats and writes a debug log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogDebug(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogDebug(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a debug log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogDebug(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogDebug(message, args);
+
+ ///
+ /// Formats and writes a debug log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogDebug("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogDebug(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogDebug(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //------------------------------------------TRACE------------------------------------------//
+
+ ///
+ /// Formats and writes a trace log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogTrace(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogTrace(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes a trace log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogTrace(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogTrace(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a trace log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogTrace(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogTrace(eventId, message, args);
+
+ ///
+ /// Formats and writes a trace log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogTrace(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogTrace(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes a trace log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogTrace(this Logger logger, Exception exception, string message, params object?[] args) =>
+ ((ILogger)logger).LogTrace(exception, message, args);
+
+ ///
+ /// Formats and writes a trace log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogTrace(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogTrace(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a trace log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogTrace(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogTrace(message, args);
+
+ ///
+ /// Formats and writes a trace log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogTrace("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogTrace(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogTrace(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //------------------------------------------INFORMATION------------------------------------------//
+
+ ///
+ /// Formats and writes an informational log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogInformation(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogInformation(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes an informational log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogInformation(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogInformation(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes an informational log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogInformation(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogInformation(eventId, message, args);
+
+ ///
+ /// Formats and writes an informational log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogInformation(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogInformation(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes an informational log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogInformation(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogInformation(exception, message, args);
+
+ ///
+ /// Formats and writes an informational log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogInformation(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogInformation(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes an informational log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogInformation(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogInformation(message, args);
+
+ ///
+ /// Formats and writes an informational log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogInformation("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogInformation(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogInformation(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //------------------------------------------WARNING------------------------------------------//
+
+ ///
+ /// Formats and writes a warning log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogWarning(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogWarning(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes a warning log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogWarning(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogWarning(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a warning log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogWarning(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogWarning(eventId, message, args);
+
+ ///
+ /// Formats and writes a warning log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogWarning(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogWarning(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes a warning log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogWarning(this Logger logger, Exception exception, string message, params object?[] args) =>
+ ((ILogger)logger).LogWarning(exception, message, args);
+
+ ///
+ /// Formats and writes a warning log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogWarning(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogWarning(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a warning log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogWarning(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogWarning(message, args);
+
+ ///
+ /// Formats and writes a warning log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogWarning("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogWarning(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogWarning(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //------------------------------------------ERROR------------------------------------------//
+
+ ///
+ /// Formats and writes an error log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogError(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogError(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes an error log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogError(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogError(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes an error log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogError(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogError(eventId, message, args);
+
+ ///
+ /// Formats and writes an error log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogError(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogError(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes an error log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogError(this Logger logger, Exception exception, string message, params object?[] args) =>
+ ((ILogger)logger).LogError(exception, message, args);
+
+ ///
+ /// Formats and writes an error log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogError(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogError(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes an error log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogError(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogError(message, args);
+
+ ///
+ /// Formats and writes an error log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogError("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogError(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogError(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //------------------------------------------CRITICAL------------------------------------------//
+
+ ///
+ /// Formats and writes a critical log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogCritical(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).LogCritical(eventId, exception, message, args);
+
+ ///
+ /// Formats and writes a critical log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(0, exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogCritical(this Logger logger,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogCritical(eventId, exception, message, args);
+#else
+ NoOp(eventId, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a critical log message.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogCritical(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ ((ILogger)logger).LogCritical(eventId, message, args);
+
+ ///
+ /// Formats and writes a critical log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The event id associated with the log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(0, "Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogCritical(this Logger logger,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogCritical(eventId, message, args);
+#else
+ NoOp(eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes a critical log message.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void
+ LogCritical(this Logger logger, Exception exception, string message, params object?[] args) =>
+ ((ILogger)logger).LogCritical(exception, message, args);
+
+ ///
+ /// Formats and writes a critical log message that contain potentially sensitive information.
+ ///
+ /// The to write to.
+ /// The exception to log.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical(exception, "Error while processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogCritical(this Logger logger,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogCritical(exception, message, args);
+#else
+ NoOp(exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a critical log message.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void LogCritical(this Logger logger, string message, params object?[] args) =>
+ ((ILogger)logger).LogCritical(message, args);
+
+ ///
+ /// Formats and writes a critical log message that contains potentially sensitive information.
+ ///
+ /// The to write to.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// logger.LogCritical("Processing request from {Address}", address)
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLogCritical(this Logger logger, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).LogCritical(message, args);
+#else
+ NoOp(message, args);
+#endif
+
+ //--------------------------------------------LOG---------------------------------------------//
+
+ ///
+ /// Formats and writes a log message at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void Log(this Logger logger, LogLevel logLevel, string message, params object?[] args) =>
+ ((ILogger)logger).Log(logLevel, 0, null, message, args);
+
+ ///
+ /// Formats and writes a log message that may contain sensitive information at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLog(this Logger logger, LogLevel logLevel, string message, params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).Log(logLevel, 0, null, message, args);
+#else
+ NoOp(logLevel, message, args);
+#endif
+
+ ///
+ /// Formats and writes a log message at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// The event id associated with the log.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+
+ public static void Log(this Logger logger,
+ LogLevel logLevel,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).Log(logLevel, eventId, null, message, args);
+
+ ///
+ /// Formats and writes a log message that may contain sensitive information at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// The event id associated with the log.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLog(this Logger logger,
+ LogLevel logLevel,
+ EventId eventId,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).Log(logLevel, eventId, null, message, args);
+#else
+ NoOp(logLevel, eventId, message, args);
+#endif
+
+ ///
+ /// Formats and writes a log message at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// The exception to log.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void Log(this Logger logger,
+ LogLevel logLevel,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).Log(logLevel, 0, exception, message, args);
+
+ ///
+ /// Formats and writes a log message that may contain sensitive information at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// The exception to log.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void SensitiveLog(this Logger logger,
+ LogLevel logLevel,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+#if ENABLE_SENSITIVE_LOG
+ ((ILogger)logger).Log(logLevel, 0, exception, message, args);
+#else
+ NoOp(logLevel, exception, message, args);
+#endif
+
+ ///
+ /// Formats and writes a log message at the specified log level.
+ ///
+ /// The to write to.
+ /// Entry will be written on this level.
+ /// The event id associated with the log.
+ /// The exception to log.
+ /// Format string of the log message.
+ /// An object array that contains zero or more objects to format.
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static void Log(this Logger logger,
+ LogLevel logLevel,
+ EventId eventId,
+ Exception exception,
+ string message,
+ params object?[] args) =>
+ ((ILogger)logger).Log(logLevel, eventId, exception, message, args);
+
+ // ///
+ // /// Formats and writes a log message that may contain sensitive information at the specified log level.
+ // ///
+ // /// The to write to.
+ // /// Entry will be written on this level.
+ // /// The event id associated with the log.
+ // /// The exception to log.
+ // /// Format string of the log message.
+ // /// An object array that contains zero or more objects to format.
+ // [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ // public static void SensitiveLog(this Logger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object?[] args) =>
+ // #if ENABLE_SENSITIVE_LOG
+ // ((ILogger)logger).Log(logLevel, eventId, exception, message, args);
+ // #else
+ // NoOp(logLevel, eventId, exception, message, args);
+ // #endif
+
+ //------------------------------------------Scope------------------------------------------//
+
+ ///
+ /// Formats the message and creates a scope.
+ ///
+ /// The to create the scope in.
+ ///
+ /// Format string of the log message in message template format.
+ /// Example: "User {User} logged in from {Address}"
+ ///
+ /// An object array that contains zero or more objects to format.
+ /// A disposable scope object. Can be null.
+ ///
+ /// using(logger.BeginScope("Processing request from {Address}", address))
+ /// {
+ /// }
+ ///
+ [Obsolete("Obsolete, use equivalent ILogger method, or view the changelog for further instruction.")]
+ public static IDisposable? BeginScope(this Logger logger,
+ string messageFormat,
+ params object?[] args) =>
+ ((ILogger)logger).BeginScope(messageFormat, args);
+ }
+}
diff --git a/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs
index 579dd303..c84cd7b2 100644
--- a/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs
+++ b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs
@@ -27,26 +27,12 @@ namespace Yubico.Core.Logging
// of Yubico.Core.Logging to only have to use one namespace (Yubico.Core.Logging), instead of two (Microsoft.Extensions.Logging
// as the second). I'm duplicating some code/API/effort in one file to avoid having to over-include in many hundreds
// of files. Files that have to include both namespaces should then hopefully be exceptional cases.
- public static class LoggerExtensions
+ public static partial class LoggerExtensions
{
// Needed to satisfy compiling out the sensitive logs in Release builds.
private static void NoOp(params object?[] _) { }
//------------------------------------------DEBUG------------------------------------------//
- ///
- /// Formats and writes a debug log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogDebug(0, exception, "Error while processing request from {Address}", address)
- public static void LogDebug(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogDebug(eventId, exception, message, args);
///
/// Formats and writes a debug log message that contains potentially sensitive information.
@@ -60,27 +46,13 @@ public static void LogDebug(this Logger logger, EventId eventId, Exception excep
///
/// An object array that contains zero or more objects to format.
/// logger.LogDebug(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogDebug(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogDebug(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogDebug(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes a debug log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogDebug(0, "Processing request from {Address}", address)
- public static void LogDebug(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogDebug(eventId, message, args);
-
///
/// Formats and writes a debug log message that contains potentially sensitive information.
///
@@ -92,27 +64,13 @@ public static void LogDebug(this Logger logger, EventId eventId, string message,
///
/// An object array that contains zero or more objects to format.
/// logger.LogDebug(0, "Processing request from {Address}", address)
- public static void SensitiveLogDebug(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogDebug(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogDebug(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes a debug log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogDebug(exception, "Error while processing request from {Address}", address)
- public static void LogDebug(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogDebug(exception, message, args);
-
///
/// Formats and writes a debug log message that contains potentially sensitive information.
///
@@ -124,26 +82,13 @@ public static void LogDebug(this Logger logger, Exception exception, string mess
///
/// An object array that contains zero or more objects to format.
/// logger.LogDebug(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogDebug(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogDebug(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogDebug(exception, message, args);
#else
NoOp(exception, message, args);
#endif
- ///
- /// Formats and writes a debug log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogDebug("Processing request from {Address}", address)
- public static void LogDebug(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogDebug(message, args);
-
///
/// Formats and writes a debug log message that contains potentially sensitive information.
///
@@ -154,7 +99,7 @@ public static void LogDebug(this Logger logger, string message, params object?[]
///
/// An object array that contains zero or more objects to format.
/// logger.LogDebug("Processing request from {Address}", address)
- public static void SensitiveLogDebug(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogDebug(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogDebug(message, args);
#else
@@ -163,21 +108,6 @@ public static void SensitiveLogDebug(this Logger logger, string message, params
//------------------------------------------TRACE------------------------------------------//
- ///
- /// Formats and writes a trace log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogTrace(0, exception, "Error while processing request from {Address}", address)
- public static void LogTrace(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogTrace(eventId, exception, message, args);
-
///
/// Formats and writes a trace log message that contains potentially sensitive information.
///
@@ -190,27 +120,13 @@ public static void LogTrace(this Logger logger, EventId eventId, Exception excep
///
/// An object array that contains zero or more objects to format.
/// logger.LogTrace(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogTrace(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogTrace(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogTrace(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes a trace log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogTrace(0, "Processing request from {Address}", address)
- public static void LogTrace(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogTrace(eventId, message, args);
-
///
/// Formats and writes a trace log message that contains potentially sensitive information.
///
@@ -222,27 +138,13 @@ public static void LogTrace(this Logger logger, EventId eventId, string message,
///
/// An object array that contains zero or more objects to format.
/// logger.LogTrace(0, "Processing request from {Address}", address)
- public static void SensitiveLogTrace(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogTrace(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogTrace(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes a trace log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogTrace(exception, "Error while processing request from {Address}", address)
- public static void LogTrace(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogTrace(exception, message, args);
-
///
/// Formats and writes a trace log message that contains potentially sensitive information.
///
@@ -254,25 +156,13 @@ public static void LogTrace(this Logger logger, Exception exception, string mess
///
/// An object array that contains zero or more objects to format.
/// logger.LogTrace(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogTrace(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogTrace(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogTrace(exception, message, args);
#else
NoOp(exception, message, args);
#endif
- ///
- /// Formats and writes a trace log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogTrace("Processing request from {Address}", address)
- public static void LogTrace(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogTrace(message, args);
///
/// Formats and writes a trace log message that contains potentially sensitive information.
@@ -284,7 +174,7 @@ public static void LogTrace(this Logger logger, string message, params object?[]
///
/// An object array that contains zero or more objects to format.
/// logger.LogTrace("Processing request from {Address}", address)
- public static void SensitiveLogTrace(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogTrace(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogTrace(message, args);
#else
@@ -293,21 +183,6 @@ public static void SensitiveLogTrace(this Logger logger, string message, params
//------------------------------------------INFORMATION------------------------------------------//
- ///
- /// Formats and writes an informational log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogInformation(0, exception, "Error while processing request from {Address}", address)
- public static void LogInformation(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogInformation(eventId, exception, message, args);
-
///
/// Formats and writes an informational log message that contains potentially sensitive information.
///
@@ -320,27 +195,13 @@ public static void LogInformation(this Logger logger, EventId eventId, Exception
///
/// An object array that contains zero or more objects to format.
/// logger.LogInformation(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogInformation(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogInformation(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogInformation(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes an informational log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogInformation(0, "Processing request from {Address}", address)
- public static void LogInformation(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogInformation(eventId, message, args);
-
///
/// Formats and writes an informational log message that contains potentially sensitive information.
///
@@ -352,27 +213,13 @@ public static void LogInformation(this Logger logger, EventId eventId, string me
///
/// An object array that contains zero or more objects to format.
/// logger.LogInformation(0, "Processing request from {Address}", address)
- public static void SensitiveLogInformation(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogInformation(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogInformation(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes an informational log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogInformation(exception, "Error while processing request from {Address}", address)
- public static void LogInformation(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogInformation(exception, message, args);
-
///
/// Formats and writes an informational log message that contains potentially sensitive information.
///
@@ -384,26 +231,13 @@ public static void LogInformation(this Logger logger, Exception exception, strin
///
/// An object array that contains zero or more objects to format.
/// logger.LogInformation(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogInformation(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogInformation(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogInformation(exception, message, args);
#else
NoOp(exception, message, args);
#endif
- ///
- /// Formats and writes an informational log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogInformation("Processing request from {Address}", address)
- public static void LogInformation(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogInformation(message, args);
-
///
/// Formats and writes an informational log message that contains potentially sensitive information.
///
@@ -414,30 +248,13 @@ public static void LogInformation(this Logger logger, string message, params obj
///
/// An object array that contains zero or more objects to format.
/// logger.LogInformation("Processing request from {Address}", address)
- public static void SensitiveLogInformation(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogInformation(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogInformation(message, args);
#else
NoOp(message, args);
#endif
- //------------------------------------------WARNING------------------------------------------//
-
- ///
- /// Formats and writes a warning log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogWarning(0, exception, "Error while processing request from {Address}", address)
- public static void LogWarning(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogWarning(eventId, exception, message, args);
-
///
/// Formats and writes a warning log message that contains potentially sensitive information.
///
@@ -450,27 +267,13 @@ public static void LogWarning(this Logger logger, EventId eventId, Exception exc
///
/// An object array that contains zero or more objects to format.
/// logger.LogWarning(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogWarning(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogWarning(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogWarning(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes a warning log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogWarning(0, "Processing request from {Address}", address)
- public static void LogWarning(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogWarning(eventId, message, args);
-
///
/// Formats and writes a warning log message that contains potentially sensitive information.
///
@@ -482,27 +285,13 @@ public static void LogWarning(this Logger logger, EventId eventId, string messag
///
/// An object array that contains zero or more objects to format.
/// logger.LogWarning(0, "Processing request from {Address}", address)
- public static void SensitiveLogWarning(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogWarning(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogWarning(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes a warning log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogWarning(exception, "Error while processing request from {Address}", address)
- public static void LogWarning(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogWarning(exception, message, args);
-
///
/// Formats and writes a warning log message that contains potentially sensitive information.
///
@@ -514,26 +303,13 @@ public static void LogWarning(this Logger logger, Exception exception, string me
///
/// An object array that contains zero or more objects to format.
/// logger.LogWarning(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogWarning(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogWarning(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogWarning(exception, message, args);
#else
NoOp(exception, message, args);
#endif
- ///
- /// Formats and writes a warning log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogWarning("Processing request from {Address}", address)
- public static void LogWarning(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogWarning(message, args);
-
///
/// Formats and writes a warning log message that contains potentially sensitive information.
///
@@ -544,7 +320,7 @@ public static void LogWarning(this Logger logger, string message, params object?
///
/// An object array that contains zero or more objects to format.
/// logger.LogWarning("Processing request from {Address}", address)
- public static void SensitiveLogWarning(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogWarning(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogWarning(message, args);
#else
@@ -553,21 +329,6 @@ public static void SensitiveLogWarning(this Logger logger, string message, param
//------------------------------------------ERROR------------------------------------------//
- ///
- /// Formats and writes an error log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogError(0, exception, "Error while processing request from {Address}", address)
- public static void LogError(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogError(eventId, exception, message, args);
-
///
/// Formats and writes an error log message that contains potentially sensitive information.
///
@@ -580,27 +341,13 @@ public static void LogError(this Logger logger, EventId eventId, Exception excep
///
/// An object array that contains zero or more objects to format.
/// logger.LogError(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogError(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogError(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogError(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes an error log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogError(0, "Processing request from {Address}", address)
- public static void LogError(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogError(eventId, message, args);
-
///
/// Formats and writes an error log message that contains potentially sensitive information.
///
@@ -612,27 +359,13 @@ public static void LogError(this Logger logger, EventId eventId, string message,
///
/// An object array that contains zero or more objects to format.
/// logger.LogError(0, "Processing request from {Address}", address)
- public static void SensitiveLogError(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogError(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogError(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes an error log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogError(exception, "Error while processing request from {Address}", address)
- public static void LogError(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogError(exception, message, args);
-
///
/// Formats and writes an error log message that contains potentially sensitive information.
///
@@ -644,26 +377,13 @@ public static void LogError(this Logger logger, Exception exception, string mess
///
/// An object array that contains zero or more objects to format.
/// logger.LogError(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogError(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogError(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogError(exception, message, args);
#else
NoOp(exception, message, args);
#endif
- ///
- /// Formats and writes an error log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogError("Processing request from {Address}", address)
- public static void LogError(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogError(message, args);
-
///
/// Formats and writes an error log message that contains potentially sensitive information.
///
@@ -674,7 +394,7 @@ public static void LogError(this Logger logger, string message, params object?[]
///
/// An object array that contains zero or more objects to format.
/// logger.LogError("Processing request from {Address}", address)
- public static void SensitiveLogError(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogError(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogError(message, args);
#else
@@ -683,21 +403,6 @@ public static void SensitiveLogError(this Logger logger, string message, params
//------------------------------------------CRITICAL------------------------------------------//
- ///
- /// Formats and writes a critical log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogCritical(0, exception, "Error while processing request from {Address}", address)
- public static void LogCritical(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogCritical(eventId, exception, message, args);
-
///
/// Formats and writes a critical log message that contains potentially sensitive information.
///
@@ -710,27 +415,13 @@ public static void LogCritical(this Logger logger, EventId eventId, Exception ex
///
/// An object array that contains zero or more objects to format.
/// logger.LogCritical(0, exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogCritical(this Logger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogCritical(eventId, exception, message, args);
#else
NoOp(eventId, exception, message, args);
#endif
- ///
- /// Formats and writes a critical log message.
- ///
- /// The to write to.
- /// The event id associated with the log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogCritical(0, "Processing request from {Address}", address)
- public static void LogCritical(this Logger logger, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).LogCritical(eventId, message, args);
-
///
/// Formats and writes a critical log message that contains potentially sensitive information.
///
@@ -742,27 +433,13 @@ public static void LogCritical(this Logger logger, EventId eventId, string messa
///
/// An object array that contains zero or more objects to format.
/// logger.LogCritical(0, "Processing request from {Address}", address)
- public static void SensitiveLogCritical(this Logger logger, EventId eventId, string message, params object?[] args) =>
+ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogCritical(eventId, message, args);
#else
NoOp(eventId, message, args);
#endif
- ///
- /// Formats and writes a critical log message.
- ///
- /// The to write to.
- /// The exception to log.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogCritical(exception, "Error while processing request from {Address}", address)
- public static void LogCritical(this Logger logger, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).LogCritical(exception, message, args);
-
///
/// Formats and writes a critical log message that contain potentially sensitive information.
///
@@ -774,26 +451,12 @@ public static void LogCritical(this Logger logger, Exception exception, string m
///
/// An object array that contains zero or more objects to format.
/// logger.LogCritical(exception, "Error while processing request from {Address}", address)
- public static void SensitiveLogCritical(this Logger logger, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLogCritical(this ILogger logger, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogCritical(exception, message, args);
#else
NoOp(exception, message, args);
#endif
-
- ///
- /// Formats and writes a critical log message.
- ///
- /// The to write to.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// logger.LogCritical("Processing request from {Address}", address)
- public static void LogCritical(this Logger logger, string message, params object?[] args) =>
- ((ILogger)logger).LogCritical(message, args);
-
///
/// Formats and writes a critical log message that contains potentially sensitive information.
///
@@ -804,7 +467,7 @@ public static void LogCritical(this Logger logger, string message, params object
///
/// An object array that contains zero or more objects to format.
/// logger.LogCritical("Processing request from {Address}", address)
- public static void SensitiveLogCritical(this Logger logger, string message, params object?[] args) =>
+ public static void SensitiveLogCritical(this ILogger logger, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).LogCritical(message, args);
#else
@@ -813,16 +476,6 @@ public static void SensitiveLogCritical(this Logger logger, string message, para
//--------------------------------------------LOG---------------------------------------------//
- ///
- /// Formats and writes a log message at the specified log level.
- ///
- /// The to write to.
- /// Entry will be written on this level.
- /// Format string of the log message.
- /// An object array that contains zero or more objects to format.
- public static void Log(this Logger logger, LogLevel logLevel, string message, params object?[] args) =>
- ((ILogger)logger).Log(logLevel, 0, null, message, args);
-
///
/// Formats and writes a log message that may contain sensitive information at the specified log level.
///
@@ -830,50 +483,13 @@ public static void Log(this Logger logger, LogLevel logLevel, string message, pa
/// Entry will be written on this level.
/// Format string of the log message.
/// An object array that contains zero or more objects to format.
- public static void SensitiveLog(this Logger logger, LogLevel logLevel, string message, params object?[] args) =>
+ public static void SensitiveLog(this ILogger logger, LogLevel logLevel, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
- ((ILogger)logger).Log(logLevel, 0, null, message, args);
+ ((ILogger)logger).Log(logLevel, 0, message, args);
#else
NoOp(logLevel, message, args);
#endif
- ///
- /// Formats and writes a log message at the specified log level.
- ///
- /// The to write to.
- /// Entry will be written on this level.
- /// The event id associated with the log.
- /// Format string of the log message.
- /// An object array that contains zero or more objects to format.
- public static void Log(this Logger logger, LogLevel logLevel, EventId eventId, string message, params object?[] args) =>
- ((ILogger)logger).Log(logLevel, eventId, null, message, args);
-
- ///
- /// Formats and writes a log message that may contain sensitive information at the specified log level.
- ///
- /// The to write to.
- /// Entry will be written on this level.
- /// The event id associated with the log.
- /// Format string of the log message.
- /// An object array that contains zero or more objects to format.
- public static void SensitiveLog(this Logger logger, LogLevel logLevel, EventId eventId, string message, params object?[] args) =>
-#if ENABLE_SENSITIVE_LOG
- ((ILogger)logger).Log(logLevel, eventId, null, message, args);
-#else
- NoOp(logLevel, eventId, message, args);
-#endif
-
- ///
- /// Formats and writes a log message at the specified log level.
- ///
- /// The to write to.
- /// Entry will be written on this level.
- /// The exception to log.
- /// Format string of the log message.
- /// An object array that contains zero or more objects to format.
- public static void Log(this Logger logger, LogLevel logLevel, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).Log(logLevel, 0, exception, message, args);
-
///
/// Formats and writes a log message that may contain sensitive information at the specified log level.
///
@@ -882,25 +498,13 @@ public static void Log(this Logger logger, LogLevel logLevel, Exception exceptio
/// The exception to log.
/// Format string of the log message.
/// An object array that contains zero or more objects to format.
- public static void SensitiveLog(this Logger logger, LogLevel logLevel, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLog(this ILogger logger, LogLevel logLevel, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).Log(logLevel, 0, exception, message, args);
#else
NoOp(logLevel, exception, message, args);
#endif
- ///
- /// Formats and writes a log message at the specified log level.
- ///
- /// The to write to.
- /// Entry will be written on this level.
- /// The event id associated with the log.
- /// The exception to log.
- /// Format string of the log message.
- /// An object array that contains zero or more objects to format.
- public static void Log(this Logger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object?[] args) =>
- ((ILogger)logger).Log(logLevel, eventId, exception, message, args);
-
///
/// Formats and writes a log message that may contain sensitive information at the specified log level.
///
@@ -910,34 +514,11 @@ public static void Log(this Logger logger, LogLevel logLevel, EventId eventId, E
/// The exception to log.
/// Format string of the log message.
/// An object array that contains zero or more objects to format.
- public static void SensitiveLog(this Logger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object?[] args) =>
+ public static void SensitiveLog(this ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object?[] args) =>
#if ENABLE_SENSITIVE_LOG
((ILogger)logger).Log(logLevel, eventId, exception, message, args);
#else
NoOp(logLevel, eventId, exception, message, args);
#endif
-
- //------------------------------------------Scope------------------------------------------//
-
- ///
- /// Formats the message and creates a scope.
- ///
- /// The to create the scope in.
- ///
- /// Format string of the log message in message template format.
- /// Example: "User {User} logged in from {Address}"
- ///
- /// An object array that contains zero or more objects to format.
- /// A disposable scope object. Can be null.
- ///
- /// using(logger.BeginScope("Processing request from {Address}", address))
- /// {
- /// }
- ///
- public static IDisposable? BeginScope(
- this Logger logger,
- string messageFormat,
- params object?[] args) =>
- ((ILogger)logger).BeginScope(messageFormat, args);
}
}
diff --git a/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs
new file mode 100644
index 00000000..41c5eaae
--- /dev/null
+++ b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs
@@ -0,0 +1,80 @@
+// Copyright 2024 Yubico AB
+//
+// Licensed under the Apache License, Version 2.0 (the "License").
+// You may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using Microsoft.Extensions.Logging;
+using Moq;
+using Xunit;
+
+namespace Yubico.Core.Logging
+{
+ public class LogTests : IDisposable
+ {
+ private readonly ILoggerFactory _originalFactory = Log.Instance;
+
+#pragma warning disable CA1816
+ public void Dispose()
+#pragma warning restore CA1816
+ {
+ // Reset to the original factory after each test
+ Log.Instance = _originalFactory;
+ }
+
+ // Ensure that the default LoggerFactory is created when no configuration is provided.
+ [Fact]
+ public void DefaultLoggerFactory_IsCreated_WhenNoConfigurationProvided()
+ {
+ // Act
+ ILoggerFactory loggerFactory = Log.Instance;
+
+ // Assert
+ Assert.NotNull(loggerFactory);
+ ILogger logger = loggerFactory.CreateLogger();
+ Assert.NotNull(logger);
+ }
+
+ // Ensure that LoggerFactory can be replaced manually using the Instance property.
+ [Fact]
+ public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory()
+ {
+ // Arrange
+ var mockLoggerFactory = new Mock();
+ Log.Instance = mockLoggerFactory.Object;
+
+ // Act
+ ILoggerFactory actualFactory = Log.Instance;
+
+ // Assert
+ Assert.Same(mockLoggerFactory.Object, actualFactory);
+ }
+
+ // Ensure that LoggerFactory can be replaced manually using the Instance property.
+ // Remove this once we remove Log.Legacy.cs
+ [Fact]
+ public void Legacy_ManualLoggerFactory_SettingInstance_OverridesDefaultFactory()
+ {
+ // Arrange
+ var mockLoggerFactory = new Mock();
+#pragma warning disable CS0618 // Type or member is obsolete
+ Log.LoggerFactory = mockLoggerFactory.Object;
+#pragma warning restore CS0618 // Type or member is obsolete
+
+ // Act
+ ILoggerFactory actualFactory = Log.Instance;
+
+ // Assert
+ Assert.Same(mockLoggerFactory.Object, actualFactory);
+ }
+ }
+}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceExtensions/ISmartCardDeviceExtension.cs b/Yubico.YubiKey/src/Yubico/YubiKey/DeviceExtensions/ISmartCardDeviceExtension.cs
index 5d7ee53c..c03ff057 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/DeviceExtensions/ISmartCardDeviceExtension.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/DeviceExtensions/ISmartCardDeviceExtension.cs
@@ -14,6 +14,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.SmartCard;
using Yubico.Core.Logging;
@@ -29,7 +30,8 @@ public static bool IsYubicoDevice(this ISmartCardDevice device)
}
catch (PlatformInterop.SCardException e)
{
- Log.GetLogger().LogWarning(e, "Exception encountered when attempting to read device ATR.");
+ Log.GetLogger(typeof(ISmartCardDeviceExtension).FullName!)
+ .LogWarning(e, "Exception encountered when attempting to read device ATR.");
}
return false;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.BioEnrollment.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.BioEnrollment.cs
index f239e920..c609fe04 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.BioEnrollment.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.BioEnrollment.cs
@@ -15,7 +15,7 @@
using System;
using System.Collections.Generic;
using System.Security;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Fido2.Commands;
namespace Yubico.YubiKey.Fido2
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Config.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Config.cs
index 1d3faf4a..43f9c48b 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Config.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Config.cs
@@ -14,7 +14,7 @@
using System;
using System.Collections.Generic;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Fido2.Commands;
namespace Yubico.YubiKey.Fido2
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.CredMgmt.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.CredMgmt.cs
index 2e38ebfa..d683ea51 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.CredMgmt.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.CredMgmt.cs
@@ -16,7 +16,7 @@
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Cryptography;
using Yubico.YubiKey.Fido2.Commands;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.GetAssertion.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.GetAssertion.cs
index 623fcb44..0f1b4615 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.GetAssertion.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.GetAssertion.cs
@@ -15,7 +15,7 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Fido2.Commands;
namespace Yubico.YubiKey.Fido2
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.LargeBlobs.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.LargeBlobs.cs
index df99a5e0..c0902613 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.LargeBlobs.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.LargeBlobs.cs
@@ -16,7 +16,7 @@
using System.Buffers.Binary;
using System.IO;
using System.Security.Cryptography;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Cryptography;
using Yubico.YubiKey.Fido2.Cbor;
using Yubico.YubiKey.Fido2.Commands;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.MakeCredential.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.MakeCredential.cs
index d568f345..4e041d8c 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.MakeCredential.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.MakeCredential.cs
@@ -14,7 +14,7 @@
using System;
using System.Security.Cryptography;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Fido2.Commands;
namespace Yubico.YubiKey.Fido2
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Pin.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Pin.cs
index 41411ecc..c64f6df3 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Pin.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.Pin.cs
@@ -15,7 +15,7 @@
using System;
using System.Globalization;
using System.Security;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Fido2.Commands;
using Yubico.YubiKey.Fido2.Cose;
using Yubico.YubiKey.Fido2.PinProtocols;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.cs
index 90d48227..9209a7d9 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Fido2Session.cs
@@ -13,6 +13,7 @@
// limitations under the License.
using System;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.YubiKey.Fido2.Commands;
@@ -65,7 +66,7 @@ namespace Yubico.YubiKey.Fido2
///
public sealed partial class Fido2Session : IDisposable
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
private bool _disposed;
private AuthenticatorInfo? _authenticatorInfo;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/LargeBlobEntry.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/LargeBlobEntry.cs
index f449ebf2..36408160 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/LargeBlobEntry.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/LargeBlobEntry.cs
@@ -18,6 +18,7 @@
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Cryptography;
using Yubico.Core.Logging;
using Yubico.YubiKey.Cryptography;
@@ -58,7 +59,7 @@ public class LargeBlobEntry
private const int AssociatedBlob = 0x626C6F62;
private const int AssociatedSizeOffset = 4;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The encrypted data. This is either the retrieved encrypted data when
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/SerializedLargeBlobArray.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/SerializedLargeBlobArray.cs
index b91bd025..124b666d 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/SerializedLargeBlobArray.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Fido2/SerializedLargeBlobArray.cs
@@ -17,6 +17,7 @@
using System.Formats.Cbor;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.YubiKey.Cryptography;
@@ -96,7 +97,7 @@ public class SerializedLargeBlobArray
{
private const int DigestLength = 16;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
private readonly List _entryList;
///
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs
index 9109ddb0..31ec8a45 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs
@@ -14,8 +14,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.Hid;
-using Yubico.Core.Logging;
using Yubico.YubiKey.DeviceExtensions;
using Yubico.YubiKey.Fido2.Commands;
using Yubico.YubiKey.U2f.Commands;
@@ -24,10 +24,9 @@ namespace Yubico.YubiKey
{
internal static class FidoDeviceInfoFactory
{
+ private static readonly ILogger Log = Core.Logging.Log.GetLogger(typeof(FidoDeviceInfoFactory).FullName!);
public static YubiKeyDeviceInfo GetDeviceInfo(IHidDevice device)
{
- Logger log = Log.GetLogger();
-
if (!device.IsYubicoDevice())
{
throw new ArgumentException(ExceptionMessages.InvalidDeviceNotYubico, nameof(device));
@@ -38,7 +37,7 @@ public static YubiKeyDeviceInfo GetDeviceInfo(IHidDevice device)
throw new ArgumentException(ExceptionMessages.InvalidDeviceNotFido, nameof(device));
}
- log.LogInformation("Getting device info for FIDO device {Device}", device);
+ Log.LogInformation("Getting device info for FIDO device {Device}", device);
if (!TryGetDeviceInfoFromFido(device, out YubiKeyDeviceInfo? ykDeviceInfo))
{
@@ -69,17 +68,15 @@ private static bool TryGetDeviceInfoFromFido(
IHidDevice device,
[MaybeNullWhen(returnValue: false)] out YubiKeyDeviceInfo deviceInfo)
{
- Logger log = Log.GetLogger();
-
try
{
- log.LogInformation("Attempting to read device info via the FIDO interface management command.");
+ Log.LogInformation("Attempting to read device info via the FIDO interface management command.");
using var connection = new FidoConnection(device);
deviceInfo = GetDeviceInfoHelper.GetDeviceInfo(connection);
if (deviceInfo is { })
{
- log.LogInformation("Successfully read device info via FIDO interface management command.");
+ Log.LogInformation("Successfully read device info via FIDO interface management command.");
return true;
}
}
@@ -99,7 +96,7 @@ private static bool TryGetDeviceInfoFromFido(
ErrorHandler(e, "Must have elevated privileges in Windows to access FIDO device directly.");
}
- log.LogWarning(
+ Log.LogWarning(
"Failed to read device info through the management interface. This may be expected for older YubiKeys.");
deviceInfo = null;
@@ -110,11 +107,9 @@ private static bool TryGetFirmwareVersionFromFido(
IHidDevice device,
[MaybeNullWhen(returnValue: false)] out FirmwareVersion firmwareVersion)
{
- Logger log = Log.GetLogger();
-
try
{
- log.LogInformation("Attempting to read firmware version through FIDO.");
+ Log.LogInformation("Attempting to read firmware version through FIDO.");
using var connection = new FidoConnection(device);
VersionResponse response = connection.SendCommand(new VersionCommand());
@@ -122,12 +117,12 @@ private static bool TryGetFirmwareVersionFromFido(
if (response.Status == ResponseStatus.Success)
{
firmwareVersion = response.GetData();
- log.LogInformation("Firmware version: {Version}", firmwareVersion.ToString());
+ Log.LogInformation("Firmware version: {Version}", firmwareVersion.ToString());
return true;
}
- log.LogError(
+ Log.LogError(
"Reading firmware version via FIDO failed with: {Error} {Message}", response.StatusWord,
response.StatusMessage);
}
@@ -147,13 +142,13 @@ private static bool TryGetFirmwareVersionFromFido(
ErrorHandler(e, "Must have elevated privileges in Windows to access FIDO device directly.");
}
- log.LogWarning("Failed to read firmware version through FIDO.");
+ Log.LogWarning("Failed to read firmware version through FIDO.");
firmwareVersion = null;
return false;
}
private static void ErrorHandler(Exception exception, string message) =>
- Log.GetLogger().LogWarning(exception, message);
+ Log.LogWarning(exception, message);
}
}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs
index 351aca57..199dcbe3 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoHelper.cs
@@ -14,13 +14,14 @@
using System;
using System.Collections.Generic;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
namespace Yubico.YubiKey
{
internal static class GetDeviceInfoHelper
{
- private static readonly Logger Logger = Log.GetLogger();
+ private static readonly ILogger Logger = Log.GetLogger(typeof(GetDeviceInfoHelper).FullName!);
///
/// Fetches and aggregates device configuration details from a YubiKey using multiple APDU commands,
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoResponseHelper.cs b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoResponseHelper.cs
index bfb2351d..f8580a86 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoResponseHelper.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/GetDeviceInfoResponseHelper.cs
@@ -14,6 +14,7 @@
using System;
using System.Collections.Generic;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
@@ -22,7 +23,7 @@ namespace Yubico.YubiKey
{
internal static class GetDeviceInfoResponseHelper
{
- private static readonly Logger Logger = Log.GetLogger();
+ private static readonly ILogger Logger = Log.GetLogger(typeof(GetDeviceInfoResponseHelper).FullName!);
///
/// Attempts to create a dictionary from a TLV-encoded byte array by parsing and extracting tag-value pairs.
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs
index 62ee6f68..9e8f981b 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/KeyboardDeviceInfoFactory.cs
@@ -14,6 +14,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Logging;
using Yubico.YubiKey.DeviceExtensions;
@@ -23,16 +24,16 @@ namespace Yubico.YubiKey
{
internal static class KeyboardDeviceInfoFactory
{
+ private static readonly ILogger Logger = Log.GetLogger(typeof(KeyboardDeviceInfoFactory).FullName!);
+
public static YubiKeyDeviceInfo GetDeviceInfo(IHidDevice device)
{
- Logger log = Log.GetLogger();
-
if (!device.IsYubicoDevice())
{
throw new ArgumentException(ExceptionMessages.InvalidDeviceNotYubico, nameof(device));
}
- log.LogInformation("Getting device info for keyboard device {Device}.", device);
+ Logger.LogInformation("Getting device info for keyboard device {Device}.", device);
if (!device.IsKeyboard())
{
@@ -69,17 +70,15 @@ public static YubiKeyDeviceInfo GetDeviceInfo(IHidDevice device)
private static bool TryGetDeviceInfoFromKeyboard(IHidDevice device, [MaybeNullWhen(returnValue: false)] out YubiKeyDeviceInfo yubiKeyDeviceInfo)
{
- Logger log = Log.GetLogger();
-
try
{
- log.LogInformation("Attempting to read device info via the management command over the keyboard interface.");
+ Logger.LogInformation("Attempting to read device info via the management command over the keyboard interface.");
using var connection = new KeyboardConnection(device);
yubiKeyDeviceInfo = GetDeviceInfoHelper.GetDeviceInfo(connection);
if (yubiKeyDeviceInfo is { })
{
- log.LogInformation("Successfully read device info via the keyboard management command.");
+ Logger.LogInformation("Successfully read device info via the keyboard management command.");
return true;
}
@@ -98,18 +97,16 @@ private static bool TryGetDeviceInfoFromKeyboard(IHidDevice device, [MaybeNullWh
"or The GetDeviceInfoResponse.GetData response data length is too long.");
}
- log.LogWarning("Failed to read device info through the keyboard management command. This may be expected for older YubiKeys.");
+ Logger.LogWarning("Failed to read device info through the keyboard management command. This may be expected for older YubiKeys.");
yubiKeyDeviceInfo = null;
return false;
}
private static bool TryGetSerialNumberFromKeyboard(IHidDevice device, out int? serialNumber)
{
- Logger log = Log.GetLogger();
-
try
{
- log.LogInformation("Attempting to read serial number through the keybaord interface.");
+ Logger.LogInformation("Attempting to read serial number through the keybaord interface.");
using var keyboardConnection = new KeyboardConnection(device);
Otp.Commands.GetSerialNumberResponse response = keyboardConnection.SendCommand(new Otp.Commands.GetSerialNumberCommand());
@@ -117,10 +114,10 @@ private static bool TryGetSerialNumberFromKeyboard(IHidDevice device, out int? s
if (response.Status == ResponseStatus.Success)
{
serialNumber = response.GetData();
- log.LogInformation("Serial number: {Serial}", serialNumber);
+ Logger.LogInformation("Serial number: {Serial}", serialNumber);
return true;
}
- log.LogError("Reading serial number via the keyboard interface failed with: {Error} {Message}", response.StatusWord, response.StatusMessage);
+ Logger.LogError("Reading serial number via the keyboard interface failed with: {Error} {Message}", response.StatusWord, response.StatusMessage);
}
catch (KeyboardConnectionException e)
{
@@ -136,18 +133,16 @@ private static bool TryGetSerialNumberFromKeyboard(IHidDevice device, out int? s
ErrorHandler(e, "The GetSerialNumberResponse.GetData response data length is too short.");
}
- log.LogWarning("Failed to read serial through the keyboard interface.");
+ Logger.LogWarning("Failed to read serial through the keyboard interface.");
serialNumber = null;
return false;
}
private static bool TryGetFirmwareVersionFromKeyboard(IHidDevice device, [MaybeNullWhen(returnValue: false)] out FirmwareVersion firmwareVersion)
{
- Logger log = Log.GetLogger();
-
try
{
- log.LogInformation("Attempting to read firmware version through the keyboard interface.");
+ Logger.LogInformation("Attempting to read firmware version through the keyboard interface.");
using var keyboardConnection = new KeyboardConnection(device);
Otp.Commands.ReadStatusResponse response = keyboardConnection.SendCommand(new Otp.Commands.ReadStatusCommand());
@@ -155,11 +150,11 @@ private static bool TryGetFirmwareVersionFromKeyboard(IHidDevice device, [MaybeN
if (response.Status == ResponseStatus.Success)
{
firmwareVersion = response.GetData().FirmwareVersion;
- log.LogInformation("Firmware version: {Version}", firmwareVersion.ToString());
+ Logger.LogInformation("Firmware version: {Version}", firmwareVersion.ToString());
return true;
}
- log.LogError("Reading firmware version via keyboard failed with: {Error} {Message}", response.StatusWord, response.StatusMessage);
+ Logger.LogError("Reading firmware version via keyboard failed with: {Error} {Message}", response.StatusWord, response.StatusMessage);
}
catch (KeyboardConnectionException e)
{
@@ -175,12 +170,12 @@ private static bool TryGetFirmwareVersionFromKeyboard(IHidDevice device, [MaybeN
ErrorHandler(e, "The length of ReadStatusCommand.GetData response data is invalid.");
}
- log.LogWarning("Failed to read firmware version through the keyboard interface.");
+ Logger.LogWarning("Failed to read firmware version through the keyboard interface.");
firmwareVersion = null;
return false;
}
private static void ErrorHandler(Exception exception, string message)
- => Log.GetLogger().LogWarning(exception, message);
+ => Logger.LogWarning(exception, message);
}
}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/KeyboardTransform.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/KeyboardTransform.cs
index 0f0542cc..d5516638 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/KeyboardTransform.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/KeyboardTransform.cs
@@ -16,6 +16,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Threading;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
@@ -31,7 +32,7 @@ internal class KeyboardTransform : IApduTransform
{
private readonly IHidConnection _hidConnection;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// An event which is fired if the YubiKey indicates it is waiting for touch. Event handlers
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/OtpErrorTransform.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/OtpErrorTransform.cs
index 7723e7e4..62eb1f7b 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/OtpErrorTransform.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/OtpErrorTransform.cs
@@ -13,6 +13,7 @@
// limitations under the License.
using System;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.YubiKey.Otp.Commands;
@@ -23,7 +24,7 @@ namespace Yubico.YubiKey.Pipelines
// be available over FIDO.
internal class OtpErrorTransform : IApduTransform
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _logger = Log.GetLogger();
private readonly IApduTransform _nextTransform;
@@ -67,7 +68,7 @@ public ResponseApdu Invoke(CommandApdu command, Type commandType, Type responseT
}
catch (KeyboardConnectionException e)
{
- _log.LogWarning(e, "Handling keyboard connection exception. Translating to APDU response.");
+ _logger.LogWarning(e, "Handling keyboard connection exception. Translating to APDU response.");
return new ResponseApdu(Array.Empty(), SWConstants.WarningNvmUnchanged);
}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/AdminData.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/AdminData.cs
index 13463261..d8d3eea9 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/AdminData.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/AdminData.cs
@@ -16,6 +16,7 @@
using System.Buffers.Binary;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
@@ -121,7 +122,7 @@ public sealed class AdminData : PivDataObject
private const byte DateRead = 4;
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// Set this to true if the PUK is blocked. If you set a YubiKey
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardCapabilityContainer.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardCapabilityContainer.cs
index bc065823..4d91d201 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardCapabilityContainer.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardCapabilityContainer.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
using Yubico.YubiKey.Cryptography;
@@ -109,7 +110,7 @@ public sealed class CardCapabilityContainer : PivDataObject
private const int UnusedTag8 = 0xFE;
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The full Unique Card Identifier which consists of the AID || CardID.
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardholderUniqueId.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardholderUniqueId.cs
index f232c378..6916f1a4 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardholderUniqueId.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/CardholderUniqueId.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
using Yubico.YubiKey.Cryptography;
@@ -87,7 +88,7 @@ public sealed class CardholderUniqueId : PivDataObject
private const int LrcTag = 0xFE;
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The "Federal Agency Smart Credential Number" (FASC-N). This is a fixed
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/KeyHistory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/KeyHistory.cs
index baedf576..dc7fe414 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/KeyHistory.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/KeyHistory.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Text;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
@@ -92,7 +93,7 @@ public sealed class KeyHistory : PivDataObject
private const int UnusedTag = 0xFE;
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// Number of Keys with On-Card Certificates. If you set this to zero,
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/PinProtectedData.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/PinProtectedData.cs
index 6c0fb8dc..e8d6e597 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/PinProtectedData.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/Objects/PinProtectedData.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
@@ -67,7 +68,7 @@ public sealed class PinProtectedData : PivDataObject
private const int MgmtKeyTag = 0x89;
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The management key that will be PIN-protected. If there is no
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs
index edb8f70e..05745d1d 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs
@@ -15,7 +15,7 @@
using System;
using System.Globalization;
using System.Security;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Piv.Commands;
namespace Yubico.YubiKey.Piv
@@ -650,7 +650,7 @@ public bool TryChangeManagementKey(PivTouchPolicy touchPolicy = PivTouchPolicy.D
///
public bool TryChangeManagementKey(PivTouchPolicy touchPolicy, PivAlgorithm newKeyAlgorithm)
{
- _log.LogInformation("Try to change the management key, touch policy = {0}, algorithm = {1}.",
+ _log.LogInformation("Try to change the management key, touch policy = {TouchPolicy}, algorithm = {PivALgorithm}.",
touchPolicy.ToString(), newKeyAlgorithm.ToString());
CheckManagementKeyAlgorithm(newKeyAlgorithm, true);
@@ -761,7 +761,7 @@ public void ChangeManagementKey(PivTouchPolicy touchPolicy = PivTouchPolicy.Defa
///
public void ChangeManagementKey(PivTouchPolicy touchPolicy, PivAlgorithm newKeyAlgorithm)
{
- _log.LogInformation("Change the management key, touch policy = {0}, algorithm = {1}.",
+ _log.LogInformation("Change the management key, touch policy = {TouchPolicy}, algorithm = {PivAlgorithm}.",
touchPolicy.ToString(), newKeyAlgorithm.ToString());
if (TryChangeManagementKey(touchPolicy, newKeyAlgorithm) == false)
@@ -914,6 +914,9 @@ private bool TryForcedChangeManagementKey(ReadOnlyMemory currentKey,
return true;
}
+
+ _log.LogInformation($"Failed to set management key. Message: {setResponse.StatusMessage}");
+
}
return false;
@@ -1036,7 +1039,6 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication,
CompleteAuthenticateManagementKeyResponse completeResponse = Connection.SendCommand(completeCommand);
ManagementKeyAuthenticationResult = completeResponse.GetData();
-
if (completeResponse.Status == ResponseStatus.Success)
{
// If Success, there are three possibilities, (1) this is
@@ -1045,8 +1047,7 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication,
// off-card app authenticated, but the YubiKey itself did
// not.
// If case (3), throw an exception.
- if (ManagementKeyAuthenticationResult ==
- AuthenticateManagementKeyResult.MutualYubiKeyAuthenticationFailed)
+ if (ManagementKeyAuthenticationResult == AuthenticateManagementKeyResult.MutualYubiKeyAuthenticationFailed)
{
throw new SecurityException(
string.Format(
@@ -1057,6 +1058,8 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication,
ManagementKeyAuthenticated = true;
}
+ _log.LogInformation($"Failed to authenticate management key. Message: {completeResponse.StatusMessage}");
+
return ManagementKeyAuthenticated;
}
}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pin.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pin.cs
index 23c6e0b7..fd508dc1 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pin.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pin.cs
@@ -15,7 +15,7 @@
using System;
using System.Globalization;
using System.Security;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Piv.Commands;
using Yubico.YubiKey.Piv.Objects;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pinonly.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pinonly.cs
index 991bcce7..cdd82b6d 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pinonly.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Pinonly.cs
@@ -16,7 +16,7 @@
using System.Globalization;
using System.Security;
using System.Security.Cryptography;
-using Yubico.Core.Logging;
+using Microsoft.Extensions.Logging;
using Yubico.YubiKey.Cryptography;
using Yubico.YubiKey.Piv.Commands;
using Yubico.YubiKey.Piv.Objects;
@@ -750,7 +750,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
public void SetPinOnlyMode(PivPinOnlyMode pinOnlyMode, PivAlgorithm mgmtKeyAlgorithm)
{
_log.LogInformation(
- "Set a YubiKey to PIV PIN-only mode: {0}, mgmt key alg = {1}.",
+ "Set a YubiKey to PIV PIN-only mode: {PivPinOnlyMode}, mgmt key alg = {PivAlgorithm}.",
pinOnlyMode.ToString(), mgmtKeyAlgorithm.ToString());
Func? userKeyCollector = KeyCollector;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.cs
index b1bbfbbd..121a2b2a 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.YubiKey.Cryptography;
@@ -151,7 +152,7 @@ namespace Yubico.YubiKey.Piv
///
public sealed partial class PivSession : IDisposable
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
private readonly IYubiKeyDevice _yubiKeyDevice;
private bool _disposed;
@@ -369,7 +370,7 @@ private void ResetAuthenticationStatus()
///
public PivMetadata GetMetadata(byte slotNumber)
{
- _log.LogInformation("GetMetadata for slot number {0:X2}.", slotNumber);
+ _log.LogInformation("GetMetadata for slot number {SlotNumber:X2}.", slotNumber);
if (!_yubiKeyDevice.HasFeature(YubiKeyFeature.PivMetadata))
{
@@ -530,7 +531,7 @@ public void MoveKey(byte sourceSlot, byte destinationSlot)
AuthenticateManagementKey();
}
- _log.LogDebug("Moving key from {sourceSlot} to {destinationSlot}", sourceSlot, destinationSlot);
+ _log.LogDebug("Moving key from {SourceSlot} to {DestinationSlot}", sourceSlot, destinationSlot);
var command = new MoveKeyCommand(sourceSlot, destinationSlot);
MoveKeyResponse response = Connection.SendCommand(command);
@@ -540,7 +541,7 @@ public void MoveKey(byte sourceSlot, byte destinationSlot)
}
_log.LogInformation(
- "Successfully moved key from {sourceSlot} to {destinationSlot}", sourceSlot, destinationSlot);
+ "Successfully moved key from {SourceSlot} to {DestinationSlot}", sourceSlot, destinationSlot);
}
///
@@ -578,7 +579,7 @@ public void DeleteKey(byte slotToClear)
AuthenticateManagementKey();
}
- _log.LogDebug("Deleting key at slot {targetSlot}", slotToClear);
+ _log.LogDebug("Deleting key at slot {TargetSlot}", slotToClear);
var command = new DeleteKeyCommand(slotToClear);
DeleteKeyResponse response = Connection.SendCommand(command);
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Scp03/Scp03Session.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Scp03/Scp03Session.cs
index 50f8c5b4..16072b12 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/Scp03/Scp03Session.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/Scp03/Scp03Session.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.YubiKey.Scp03.Commands;
@@ -79,7 +80,7 @@ namespace Yubico.YubiKey.Scp03
public sealed class Scp03Session : IDisposable
{
private bool _disposed;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The object that represents the connection to the YubiKey. Most
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardConnection.cs b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardConnection.cs
index 6ebd3936..f9590baa 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardConnection.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardConnection.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Linq;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Buffers;
using Yubico.Core.Devices.SmartCard;
using Yubico.Core.Iso7816;
@@ -26,7 +27,7 @@ namespace Yubico.YubiKey
{
internal class SmartCardConnection : IYubiKeyConnection
{
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
private readonly YubiKeyApplication _yubiKeyApplication;
private readonly byte[]? _applicationId;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs
index 93064636..26ee4d31 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/SmartCardDeviceInfoFactory.cs
@@ -14,6 +14,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.SmartCard;
using Yubico.Core.Logging;
using Yubico.YubiKey.DeviceExtensions;
@@ -26,7 +27,7 @@ internal static class SmartCardDeviceInfoFactory
public static YubiKeyDeviceInfo GetDeviceInfo(
ISmartCardDevice device)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
if (!device.IsYubicoDevice())
{
@@ -85,7 +86,7 @@ private static bool TryGetDeviceInfoFromManagement(
ISmartCardDevice device,
[MaybeNullWhen(returnValue: false)] out YubiKeyDeviceInfo deviceInfo)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
try
{
@@ -120,7 +121,7 @@ private static bool TryGetFirmwareVersionFromOtp(
ISmartCardDevice device,
[MaybeNullWhen(returnValue: false)] out FirmwareVersion firmwareVersion)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
try
{
@@ -163,7 +164,7 @@ private static bool TryGetFirmwareVersionFromPiv(
ISmartCardDevice device,
[MaybeNullWhen(returnValue: false)] out FirmwareVersion firmwareVersion)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
try
{
@@ -201,7 +202,7 @@ private static bool TryGetSerialNumberFromOtp(
ISmartCardDevice device,
out int? serialNumber)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
try
{
@@ -245,7 +246,7 @@ private static bool TryGetSerialNumberFromPiv(
ISmartCardDevice device,
out int? serialNumber)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!);
try
{
@@ -283,6 +284,7 @@ private static bool TryGetSerialNumberFromPiv(
private static void ErrorHandler(
Exception exception,
string message) =>
- Log.GetLogger().LogWarning(exception, message);
+ Log.GetLogger(typeof(SmartCardDeviceInfoFactory).FullName!)
+ .LogWarning(exception, message);
}
}
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/AuthenticationData.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/AuthenticationData.cs
index c0ea4a60..8c9e5798 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/AuthenticationData.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/AuthenticationData.cs
@@ -15,6 +15,7 @@
using System;
using System.Buffers.Binary;
using System.Globalization;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.YubiKey.Cryptography;
@@ -55,7 +56,7 @@ public class AuthenticationData : U2fSignedData
private const int SignatureOffset = ClientDataOffset + ClientDataHashLength;
private const int PayloadLength = AppIdHashLength + ClientDataHashLength + CounterLength + MaxBerSignatureLength + 1;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// If the user's presence was verified in the authentication operation,
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/RegistrationData.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/RegistrationData.cs
index 02772002..59ed3e77 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/RegistrationData.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/RegistrationData.cs
@@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Logging;
using Yubico.Core.Tlv;
using Yubico.YubiKey.Cryptography;
@@ -67,7 +68,7 @@ public class RegistrationData : U2fSignedData
private const int SignatureOffset = PublicKeyOffset + PublicKeyLength;
private const int PayloadLength = AppIdHashLength + ClientDataHashLength + KeyHandleLength + PublicKeyLength + MaxBerSignatureLength + 1;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
///
/// The ECDSA public key for this user credential. Each coordinate must
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.Pin.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.Pin.cs
index 4dc3d75a..0fc2a260 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.Pin.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.Pin.cs
@@ -15,8 +15,8 @@
using System;
using System.Globalization;
using System.Security;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
-using Yubico.Core.Logging;
using Yubico.YubiKey.U2f.Commands;
namespace Yubico.YubiKey.U2f
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.cs b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.cs
index 0d0cb4b1..61be105c 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/U2f/U2fSession.cs
@@ -21,6 +21,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.YubiKey.Cryptography;
@@ -76,7 +77,7 @@ public sealed partial class U2fSession : IDisposable
{
private const double MaxTimeoutSeconds = 30.0;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
private bool _disposed;
// The default constructor is explicitly defined to show that we do not want it used.
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs
index a8af0e35..d9277e6a 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Instance.cs
@@ -16,6 +16,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Devices.SmartCard;
@@ -108,7 +109,7 @@ public partial class YubiKeyDevice : IYubiKeyDevice
private IYubiKeyDeviceInfo _yubiKeyInfo;
private Transport _lastActiveTransport;
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
internal ISmartCardDevice GetSmartCardDevice() => _smartCardDevice!;
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Static.cs b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Static.cs
index 5089776c..f97b548f 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Static.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDevice.Static.cs
@@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Devices.SmartCard;
@@ -72,7 +73,7 @@ public partial class YubiKeyDevice
///
public static IEnumerable FindByTransport(Transport transport = Transport.All)
{
- Logger log = Log.GetLogger();
+ ILogger log = Log.GetLogger(typeof(YubiKeyDeviceListener).FullName!);
log.LogInformation("FindByTransport {Transport}", transport);
diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceListener.cs b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceListener.cs
index 96e2a338..66907d6b 100644
--- a/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceListener.cs
+++ b/Yubico.YubiKey/src/Yubico/YubiKey/YubiKeyDeviceListener.cs
@@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using Microsoft.Extensions.Logging;
using Yubico.Core.Devices;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Devices.SmartCard;
@@ -50,7 +51,8 @@ public class YubiKeyDeviceListener : IDisposable
private static readonly ReaderWriterLockSlim RwLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
- private readonly Logger _log = Log.GetLogger();
+ private readonly ILogger _log = Log.GetLogger();
+
private readonly Dictionary _internalCache = new Dictionary();
private readonly HidDeviceListener _hidListener = HidDeviceListener.Create();
private readonly SmartCardDeviceListener _smartCardListener = SmartCardDeviceListener.Create();
@@ -60,8 +62,6 @@ public class YubiKeyDeviceListener : IDisposable
private YubiKeyDeviceListener()
{
- _log.LogInformation("Creating YubiKeyDeviceListener instance.");
-
_listenerThread = new Thread(ListenForChanges) { IsBackground = true };
_isListening = true;
@@ -346,7 +346,9 @@ private static IEnumerable GetSmartCardDevices()
}
private static void ErrorHandler(Exception exception) =>
- Log.GetLogger().LogWarning($"Exception caught: {exception}");
+ Log
+ .GetLogger(typeof(YubiKeyDeviceListener).FullName!)
+ .LogWarning($"Exception caught: {exception}");
#region IDisposable Support
diff --git a/Yubico.YubiKey/tests/integration/Yubico.YubiKey.IntegrationTests.csproj b/Yubico.YubiKey/tests/integration/Yubico.YubiKey.IntegrationTests.csproj
index ed94ddcb..ad352daf 100644
--- a/Yubico.YubiKey/tests/integration/Yubico.YubiKey.IntegrationTests.csproj
+++ b/Yubico.YubiKey/tests/integration/Yubico.YubiKey.IntegrationTests.csproj
@@ -35,7 +35,7 @@ limitations under the License. -->
-
+
@@ -48,5 +48,9 @@ limitations under the License. -->
PreserveNewest
+
+
+ PreserveNewest
+
diff --git a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/GetAuthenticatorInfoTests.cs b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/GetAuthenticatorInfoTests.cs
index f2466f61..773d483b 100644
--- a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/GetAuthenticatorInfoTests.cs
+++ b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/GetAuthenticatorInfoTests.cs
@@ -21,7 +21,7 @@ namespace Yubico.YubiKey.Fido2
public class GetAuthenticatorInfoTests
{
[Fact]
- [Trait(TraitTypes.Category, TestCategories.Simple)]
+ [Trait(TraitTypes.Category, TestCategories.Elevated)]
public void GetAuthenticator_Succeeds()
{
IYubiKeyDevice yubiKey = YubiKeyDevice.FindAll().First();
diff --git a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/MakeCredentialGetAssertionTests.cs b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/MakeCredentialGetAssertionTests.cs
index 44e81fdc..5225af4e 100644
--- a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/MakeCredentialGetAssertionTests.cs
+++ b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/Fido2/MakeCredentialGetAssertionTests.cs
@@ -203,7 +203,7 @@ public void MakeCredential_MultipleCredentials_GetAssertion_ReturnsMultipleAsser
// This test requires user to touch the device.
- [Theory, Trait("Category", "RequiresTouch")]
+ [Theory, Trait(TraitTypes.Category, TestCategories.RequiresTouch)]
[InlineData(CredProtectPolicy.UserVerificationOptional, true)]
[InlineData(CredProtectPolicy.UserVerificationOptional, false)]
[InlineData(CredProtectPolicy.UserVerificationRequired, true)]
@@ -219,7 +219,7 @@ public void AddCredProtectExtension_KeySupportsCredProtectExtension(
TestAddCredProtectExtension(expectExtensionSupported: true, credProtectPolicy, enforceCredProtectPolicy);
}
- [Theory, Trait("Category", "RequiresTouch")]
+ [Theory, Trait(TraitTypes.Category, TestCategories.RequiresTouch)]
[InlineData(CredProtectPolicy.UserVerificationOptional, true)]
[InlineData(CredProtectPolicy.UserVerificationOptional, false)]
[InlineData(CredProtectPolicy.UserVerificationRequired, true)]
diff --git a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs
index 64dd5b0b..6240e52f 100644
--- a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs
+++ b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs
@@ -25,6 +25,7 @@
using Yubico.YubiKey.Piv;
using Yubico.YubiKey.TestUtilities;
using Log = Yubico.Core.Logging.Log;
+using Logger = Serilog.Core.Logger;
namespace Yubico.YubiKey
{
@@ -52,8 +53,9 @@ public void SwitchingBetweenTransports_ForcesThreeSecondWait()
outputTemplate: "{Timestamp:HH:mm:ss.fffffff} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}")
.CreateLogger();
- Log.LoggerFactory = LoggerFactory.Create(
- builder => builder
+ Log.ConfigureLoggerFactory(builder =>
+ builder
+ .ClearProviders()
.AddSerilog(log)
.AddFilter(level => level >= LogLevel.Information));
diff --git a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/U2f/PinTests.cs b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/U2f/PinTests.cs
index a081e5e0..5d75228b 100644
--- a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/U2f/PinTests.cs
+++ b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/U2f/PinTests.cs
@@ -13,7 +13,6 @@
// limitations under the License.
using System;
-using System.Collections.Generic;
using Xunit;
using Yubico.Core.Devices.Hid;
using Yubico.Core.Iso7816;
diff --git a/Yubico.YubiKey/tests/integration/appsettings.json b/Yubico.YubiKey/tests/integration/appsettings.json
new file mode 100644
index 00000000..48610693
--- /dev/null
+++ b/Yubico.YubiKey/tests/integration/appsettings.json
@@ -0,0 +1,11 @@
+{
+ "AppName": "Integration",
+ "Logging": {
+ "LogLevel": {
+ "Yubico": "Debug"
+ },
+ "Console": {
+ "IncludeScopes": true,
+ }
+ }
+}
diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs
index 01293b04..96c580b7 100644
--- a/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs
+++ b/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs
@@ -17,6 +17,8 @@
using Serilog;
using Serilog.Core;
using Serilog.Events;
+using Log = Yubico.Core.Logging.Log;
+using Logger = Serilog.Core.Logger;
namespace Yubico.YubiKey.TestApp.Plugins
{
@@ -44,11 +46,10 @@ public override bool Execute()
outputTemplate: "[{Level}] ({ThreadId}) {Message}{NewLine}{Exception}")
.CreateLogger();
- Core.Logging.Log.LoggerFactory = LoggerFactory.Create(
- builder => builder
+ Log.ConfigureLoggerFactory(builder =>
+ builder
.AddSerilog(log)
.AddFilter(level => level >= LogLevel.Information));
-
YubiKeyDeviceListener.Instance.Arrived += (s, e) =>
{
Console.WriteLine("YubiKey arrived:");
diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs
index 88936115..01505a9b 100644
--- a/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs
+++ b/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs
@@ -14,8 +14,6 @@
using System;
using System.Linq;
-using Microsoft.Extensions.Logging;
-using Serilog;
namespace Yubico.YubiKey.TestApp.Plugins
{
@@ -28,21 +26,6 @@ public GregPlugin(IOutput output) : base(output) { }
public override bool Execute()
{
- using Serilog.Core.Logger? log = new LoggerConfiguration()
- .Enrich.With(new ThreadIdEnricher())
- .WriteTo.Console(
- outputTemplate: "[{Level}] ({ThreadId}) {Message}{NewLine}{Exception}")
- .CreateLogger();
-
- Core.Logging.Log.LoggerFactory = LoggerFactory.Create(
- builder => builder
- .AddSerilog(log)
- .AddFilter(level => level >= LogLevel.Information));
-
-
-
-
-
IYubiKeyDevice? yubiKey = YubiKeyDevice.FindByTransport(Transport.All).First();
// IYubiKeyDevice? yubiKey = YubiKeyDevice.FindByTransport(Transport.HidFido).First();
@@ -54,5 +37,8 @@ public override bool Execute()
return true;
}
+
}
+
+
}
diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/HidDeviceListenerPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/HidDeviceListenerPlugin.cs
index d98b1dad..2b3bac6e 100644
--- a/Yubico.YubiKey/tests/sandbox/Plugins/HidDeviceListenerPlugin.cs
+++ b/Yubico.YubiKey/tests/sandbox/Plugins/HidDeviceListenerPlugin.cs
@@ -13,9 +13,7 @@
// limitations under the License.
using System;
-using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.Hid;
-using Yubico.Core.Logging;
namespace Yubico.YubiKey.TestApp.Plugins
{
@@ -30,16 +28,6 @@ public HidDeviceListenerPlugin(IOutput output) : base(output)
public override bool Execute()
{
- Log.LoggerFactory = LoggerFactory.Create(
- builder => builder.AddSimpleConsole(
- options =>
- {
- options.IncludeScopes = true;
- options.SingleLine = true;
- options.TimestampFormat = "hh:mm:ss";
- })
- .AddFilter(level => level >= LogLevel.Information));
-
Console.WriteLine("Create listener");
var listener = HidDeviceListener.Create();
diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/OathPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/OathPlugin.cs
index 8f42eff2..c619a581 100644
--- a/Yubico.YubiKey/tests/sandbox/Plugins/OathPlugin.cs
+++ b/Yubico.YubiKey/tests/sandbox/Plugins/OathPlugin.cs
@@ -15,8 +15,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Microsoft.Extensions.Logging;
-using Yubico.Core.Logging;
using Yubico.YubiKey.Oath;
namespace Yubico.YubiKey.TestApp.Plugins
@@ -31,20 +29,9 @@ public OathPlugin(IOutput output) : base(output) { }
public override bool Execute()
{
- Log.LoggerFactory = LoggerFactory.Create(
- builder => builder.AddSimpleConsole(
- options =>
- {
- options.IncludeScopes = true;
- options.SingleLine = true;
- options.TimestampFormat = "hh:mm:ss";
- })
- .AddFilter(level => level >= LogLevel.Information));
-
IEnumerable keys = YubiKeyDevice.FindAll();
IYubiKeyDevice? yubiKey = keys.First();
-
using var oathSession = new OathSession(yubiKey);
// Copy URI string from Authenticator Test console and pass here.
diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/SmartCardDeviceListenerPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/SmartCardDeviceListenerPlugin.cs
index 51f0d3c6..0fe80341 100644
--- a/Yubico.YubiKey/tests/sandbox/Plugins/SmartCardDeviceListenerPlugin.cs
+++ b/Yubico.YubiKey/tests/sandbox/Plugins/SmartCardDeviceListenerPlugin.cs
@@ -13,9 +13,7 @@
// limitations under the License.
using System;
-using Microsoft.Extensions.Logging;
using Yubico.Core.Devices.SmartCard;
-using Yubico.Core.Logging;
using Yubico.YubiKey.InterIndustry.Commands;
namespace Yubico.YubiKey.TestApp.Plugins
@@ -31,16 +29,6 @@ public SmartCardDeviceListenerPlugin(IOutput output) : base(output)
public override bool Execute()
{
- Log.LoggerFactory = LoggerFactory.Create(
- builder => builder.AddSimpleConsole(
- options =>
- {
- options.IncludeScopes = true;
- options.SingleLine = true;
- options.TimestampFormat = "hh:mm:ss";
- })
- .AddFilter(level => level >= LogLevel.Information));
-
Console.WriteLine("Create listener");
var listener = SmartCardDeviceListener.Create();
diff --git a/Yubico.YubiKey/tests/sandbox/Yubico.YubiKey.TestApp.csproj b/Yubico.YubiKey/tests/sandbox/Yubico.YubiKey.TestApp.csproj
index 557c0cf9..e7ebd6e3 100644
--- a/Yubico.YubiKey/tests/sandbox/Yubico.YubiKey.TestApp.csproj
+++ b/Yubico.YubiKey/tests/sandbox/Yubico.YubiKey.TestApp.csproj
@@ -34,7 +34,7 @@ limitations under the License. -->
-
+
@@ -47,4 +47,10 @@ limitations under the License. -->
+
+
+ PreserveNewest
+
+
+
diff --git a/Yubico.YubiKey/tests/sandbox/appsettings.json b/Yubico.YubiKey/tests/sandbox/appsettings.json
new file mode 100644
index 00000000..9e6820cf
--- /dev/null
+++ b/Yubico.YubiKey/tests/sandbox/appsettings.json
@@ -0,0 +1,11 @@
+{
+ "AppName": "Sandbox",
+ "Logging": {
+ "LogLevel": {
+ "Yubico": "Debug"
+ },
+ "Console": {
+ "IncludeScopes": true
+ }
+ }
+}
diff --git a/Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj b/Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
index d1bf6343..e61a4e09 100644
--- a/Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
+++ b/Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
@@ -39,4 +39,10 @@ limitations under the License. -->
+
+
+
+ PreserveNewest
+
+
diff --git a/Yubico.YubiKey/tests/unit/appsettings.json b/Yubico.YubiKey/tests/unit/appsettings.json
new file mode 100644
index 00000000..01a36f0b
--- /dev/null
+++ b/Yubico.YubiKey/tests/unit/appsettings.json
@@ -0,0 +1,11 @@
+{
+ "AppName": "UnitTests",
+ "Logging": {
+ "LogLevel": {
+ "Yubico": "Debug"
+ },
+ "Console": {
+ "IncludeScopes": true
+ }
+ }
+}
diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs
index 588283a9..8da5e7d6 100644
--- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs
+++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs
@@ -89,7 +89,7 @@ public IntegrationTestDeviceEnumeration(string? configDirectory = null)
///
///
///
- public static IYubiKeyDevice GetBySerial(int serialNumber)
+ public static IYubiKeyDevice GetBySerial(int serialNumber)
=> GetTestDevices().Single(d => d.SerialNumber == serialNumber);
///
@@ -116,7 +116,7 @@ static bool IsAllowedKey(IYubiKeyDevice key)
/// The allow-list filtered YubiKey that was found.
public static IYubiKeyDevice GetTestDevice(
StandardTestDevice testDeviceType = StandardTestDevice.Fw5,
- Transport transport = Transport.All)
+ Transport transport = Transport.All)
=> GetTestDevices(transport)
.SelectByStandardTestDevice(testDeviceType);
@@ -132,7 +132,7 @@ public static IYubiKeyDevice GetTestDevice(Transport transport, FirmwareVersion
=> GetTestDevices(transport)
.SelectByMinimumVersion(minimumFirmwareVersion);
-
+
private static void CreateAllowListFileIfMissing(string allowListFilePath)
{
if (File.Exists(allowListFilePath))
diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs
index 5b4b01ae..9d868380 100644
--- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs
+++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs
@@ -22,28 +22,28 @@ public static class TestCategories
/// aware of when touch is about to be expected.
///
public const string RequiresTouch = "RequiresTouch";
-
+
///
/// These tests are considered to be simple and should not require any special circumstances to run successfully.
///
public const string Simple = "Simple";
-
+
///
/// These tests require that you run your tests in an elevated session, e.g. 'Run as Administrator' on Windows.
/// For example, all FIDO tests require an elevated session on Windows.
///
- public const string Elevated = "Elevated";
-
+ public const string Elevated = "Elevated";
+
///
/// These tests require a Yubikey with biometric capabilities
///
- public const string RequiresBio = "RequiresBio";
-
+ public const string RequiresBio = "RequiresBio";
+
///
/// These tests require certain setup on the Yubikey in order to succeed.
///
- public const string RequiresSetup = "RequiresSetup";
-
+ public const string RequiresSetup = "RequiresSetup";
+
///
/// These tests may require step debugging to avoid timing issues
///
@@ -54,7 +54,7 @@ public static class TestCategories
///
public const string RequiresFips = "RequiresFips";
}
-
+
public static class TraitTypes
{
public const string Category = "Category";
diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs
index ea0bf63c..09662c0e 100644
--- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs
+++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs
@@ -84,9 +84,9 @@ IYubiKeyDevice SelectDevice(int majorVersion, FormFactor? formFactor = null, boo
IYubiKeyDevice device = null!;
try
{
- bool MatchingDeviceSelector(IYubiKeyDevice d) =>
- d.FirmwareVersion.Major == majorVersion &&
- (formFactor is null || d.FormFactor == formFactor) &&
+ bool MatchingDeviceSelector(IYubiKeyDevice d) =>
+ d.FirmwareVersion.Major == majorVersion &&
+ (formFactor is null || d.FormFactor == formFactor) &&
d.IsFipsSeries == isFipsSeries;
device = devices.First(MatchingDeviceSelector);
@@ -115,25 +115,25 @@ public static IYubiKeyDevice SelectByMinimumVersion(
{
ThrowDeviceNotFoundException("No matching YubiKey found", devices);
}
-
+
return device!;
}
- private static void ThrowDeviceNotFoundException(string errorMessage,IYubiKeyDevice[] devices)
+ private static void ThrowDeviceNotFoundException(string errorMessage, IYubiKeyDevice[] devices)
{
var connectedDevicesText = FormatConnectedDevices(devices);
throw new DeviceNotFoundException($"{errorMessage}. {connectedDevicesText}");
}
private static string FormatConnectedDevices(IReadOnlyCollection devices)
- {
- var deviceText =
- devices.Select(y => $"{{{y.FirmwareVersion}, {y.FormFactor}, IsFipsSeries: {y.IsFipsSeries}}}");
-
- return devices.Any()
- ? $"Connected devices: {string.Join(", ", deviceText)}"
- : string.Empty;
- }
+ {
+ var deviceText =
+ devices.Select(y => $"{{{y.FirmwareVersion}, {y.FormFactor}, IsFipsSeries: {y.IsFipsSeries}}}");
+
+ return devices.Any()
+ ? $"Connected devices: {string.Join(", ", deviceText)}"
+ : string.Empty;
+ }
}
// Custom test exception inheriting from InvalidOperationException as some test code depends on InvalidOperationExceptions