Skip to content

Commit

Permalink
Revert name change of logger instance
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisDyallo committed Aug 13, 2024
1 parent e116b2e commit 8bb3072
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 106 deletions.
6 changes: 3 additions & 3 deletions Yubico.Core/src/Yubico/Core/Devices/Hid/HidDeviceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Yubico.Core.Devices.Hid
/// </remarks>
public abstract class HidDeviceListener
{
private readonly ILogger _logger = Logging.Log.GetLogger<HidDeviceListener>();
private readonly ILogger _log = Logging.Log.GetLogger<HidDeviceListener>();

/// <summary>
/// Subscribe to receive an event whenever a Human Interface Device (HID) is added to the computer.
Expand Down Expand Up @@ -75,7 +75,7 @@ public static HidDeviceListener Create() =>
/// </param>
protected void OnArrived(IHidDevice device)
{
_logger.LogInformation("HID {Device} arrived.", device);
_log.LogInformation("HID {Device} arrived.", device);
Arrived?.Invoke(this, new HidDeviceEventArgs(device));
}

Expand All @@ -88,7 +88,7 @@ protected void OnArrived(IHidDevice device)
/// </param>
protected void OnRemoved(IHidDevice? device)
{
_logger.LogInformation("HID {Device} removed.", device);
_log.LogInformation("HID {Device} removed.", device);
Removed?.Invoke(this, new HidDeviceEventArgs(device));
}

Expand Down
6 changes: 3 additions & 3 deletions Yubico.Core/src/Yubico/Core/Devices/Hid/MacOSHidDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace Yubico.Core.Devices.Hid
internal class MacOSHidDevice : HidDevice
{
private readonly long _entryId;
private readonly ILogger _logger = Logging.Log.GetLogger<MacOSHidDevice>();
private readonly ILogger _log = Logging.Log.GetLogger<MacOSHidDevice>();

public MacOSHidDevice(long entryId) :
base(entryId.ToString(CultureInfo.InvariantCulture))
{
_logger.LogInformation(
_log.LogInformation(
$"Creating new instance of MacOSHidDevice based on device with EntryID [{entryId}]",
entryId);

Expand Down Expand Up @@ -136,7 +136,7 @@ internal static long GetEntryId(IntPtr device)
public void LogDeviceAccessTime()
{
LastAccessed = DateTime.Now;
_logger.LogInformation("Updating last used for {Device} to {LastAccessed:hh:mm:ss.fffffff}", this, LastAccessed);
_log.LogInformation("Updating last used for {Device} to {LastAccessed:hh:mm:ss.fffffff}", this, LastAccessed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Linq;
using Microsoft.Extensions.Logging;
using Yubico.Core.Iso7816;
using Yubico.Core.Logging;
using Yubico.PlatformInterop;

using static Yubico.PlatformInterop.NativeMethods;
Expand All @@ -27,14 +28,15 @@ namespace Yubico.Core.Devices.SmartCard
internal class DesktopSmartCardDevice : SmartCardDevice
{
private readonly string _readerName;
private static readonly ILogger Logger = Logging.Log.GetLogger<DesktopSmartCardDevice>();
private readonly ILogger _log = Log.GetLogger<DesktopSmartCardDevice>();

public static IReadOnlyList<ISmartCardDevice> GetList()
{
using IDisposable? logScope = Logger.BeginScope("SmartCardDevice.GetList()");
ILogger log = Log.GetLogger<DesktopSmartCardDevice>();
using IDisposable? logScope = log.BeginScope("SmartCardDevice.GetList()");

uint result = SCardEstablishContext(SCARD_SCOPE.USER, out SCardContext context);
Logger.SCardApiCall(nameof(SCardEstablishContext), result);
log.SCardApiCall(nameof(SCardEstablishContext), result);

if (result != ErrorCode.SCARD_S_SUCCESS)
{
Expand All @@ -49,19 +51,19 @@ public static IReadOnlyList<ISmartCardDevice> GetList()

if (result != ErrorCode.SCARD_E_NO_READERS_AVAILABLE)
{
Logger.SCardApiCall(nameof(SCardListReaders), result);
log.SCardApiCall(nameof(SCardListReaders), result);
}

// It's OK if there are no readers on the system. Treat this the same as if we
// didn't find any devices.
if (result == ErrorCode.SCARD_E_NO_READERS_AVAILABLE || readerNames.Length == 0)
{
Logger.LogInformation("No smart card devices found.");
log.LogInformation("No smart card devices found.");

return new List<ISmartCardDevice>();
}

Logger.LogInformation("Found {NumSmartCards} smart card devices.", readerNames.Length);
log.LogInformation("Found {NumSmartCards} smart card devices.", readerNames.Length);

if (result != ErrorCode.SCARD_S_SUCCESS)
{
Expand All @@ -78,8 +80,8 @@ public static IReadOnlyList<ISmartCardDevice> GetList()
readerStates,
readerStates.Length);

Logger.SCardApiCall(nameof(SCardGetStatusChange), result);
Logger.LogInformation("Updated SCard reader states: {ReaderStates}", readerStates);
log.SCardApiCall(nameof(SCardGetStatusChange), result);
log.LogInformation("Updated SCard reader states: {ReaderStates}", readerStates);

if (result != ErrorCode.SCARD_S_SUCCESS)
{
Expand Down Expand Up @@ -116,7 +118,7 @@ public DesktopSmartCardDevice(string readerName, AnswerToReset? atr) :
public override ISmartCardConnection Connect()
{
uint result = SCardEstablishContext(SCARD_SCOPE.USER, out SCardContext? context);
Logger.SCardApiCall(nameof(SCardEstablishContext), result);
_log.SCardApiCall(nameof(SCardEstablishContext), result);

if (result != ErrorCode.SCARD_S_SUCCESS)
{
Expand Down Expand Up @@ -145,7 +147,7 @@ public override ISmartCardConnection Connect()
out cardHandle,
out SCARD_PROTOCOL activeProtocol);

Logger.SCardApiCall(nameof(SCardConnect), result);
_log.SCardApiCall(nameof(SCardConnect), result);

if (result != ErrorCode.SCARD_S_SUCCESS)
{
Expand All @@ -157,7 +159,7 @@ public override ISmartCardConnection Connect()
result);
}

Logger.LogInformation(
_log.LogInformation(
"Connected to smart card [{ReaderName}]. Active protocol is [{ActiveProtocol}]",
_readerName,
activeProtocol);
Expand All @@ -169,7 +171,7 @@ public override ISmartCardConnection Connect()
activeProtocol);

// We are transferring ownership to SmartCardConnection
Logger.LogInformation("Transferred context and cardHandle to connection instance.");
_log.LogInformation("Transferred context and cardHandle to connection instance.");
context = null;
cardHandle = null;

Expand All @@ -180,21 +182,21 @@ public override ISmartCardConnection Connect()
if (context != null)
{
context?.Dispose();
Logger.LogInformation("Context disposed.");
_log.LogInformation("Context disposed.");
}

if (cardHandle != null)
{
cardHandle?.Dispose();
Logger.LogInformation("CardHandle disposed.");
_log.LogInformation("CardHandle disposed.");
}
}
}

public void LogDeviceAccessTime()
{
LastAccessed = DateTime.Now;
Logger.LogInformation("Updating last used for {Device} to {LastAccessed:hh:mm:ss.fffffff}", this, LastAccessed);
_log.LogInformation("Updating last used for {Device} to {LastAccessed:hh:mm:ss.fffffff}", this, LastAccessed);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Yubico.YubiKey/src/Yubico/YubiKey/FidoDeviceInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Yubico.YubiKey
{
internal static class FidoDeviceInfoFactory
{
private static readonly ILogger Log = Core.Logging.Log.GetLogger("Yubico.YubiKey.FidoDeviceInfoFactory");
private static readonly ILogger Log = Core.Logging.Log.GetLogger(typeof(FidoDeviceInfoFactory).FullName!);
public static YubiKeyDeviceInfo GetDeviceInfo(IHidDevice device)
{
if (!device.IsYubicoDevice())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public sealed partial class PivSession : IDisposable
/// </exception>
public bool TryAuthenticateManagementKey(bool mutualAuthentication = true)
{
_logger.LogInformation(
_log.LogInformation(
$"Try to authenticate the management key: {(mutualAuthentication ? "mutual" : "single")} auth.");

PivPinOnlyMode currentMode = TryAuthenticatePinOnly(true);
Expand Down Expand Up @@ -309,7 +309,7 @@ private bool TryAuthenticateWithKeyCollector(bool mutualAuthentication)
/// </exception>
public void AuthenticateManagementKey(bool mutualAuthentication = true)
{
_logger.LogInformation(
_log.LogInformation(
$"Authenticate the management key: {(mutualAuthentication ? "mutual" : "single")} auth.");

if (TryAuthenticateManagementKey(mutualAuthentication) == false)
Expand Down Expand Up @@ -650,7 +650,7 @@ public bool TryChangeManagementKey(PivTouchPolicy touchPolicy = PivTouchPolicy.D
/// </exception>
public bool TryChangeManagementKey(PivTouchPolicy touchPolicy, PivAlgorithm newKeyAlgorithm)
{
_logger.LogInformation("Try to change the management key, touch policy = {TouchPolicy}, algorithm = {PivALgorithm}.",
_log.LogInformation("Try to change the management key, touch policy = {TouchPolicy}, algorithm = {PivALgorithm}.",
touchPolicy.ToString(), newKeyAlgorithm.ToString());

CheckManagementKeyAlgorithm(newKeyAlgorithm, true);
Expand Down Expand Up @@ -761,7 +761,7 @@ public void ChangeManagementKey(PivTouchPolicy touchPolicy = PivTouchPolicy.Defa
/// </exception>
public void ChangeManagementKey(PivTouchPolicy touchPolicy, PivAlgorithm newKeyAlgorithm)
{
_logger.LogInformation("Change the management key, touch policy = {TouchPolicy}, algorithm = {PivAlgorithm}.",
_log.LogInformation("Change the management key, touch policy = {TouchPolicy}, algorithm = {PivAlgorithm}.",
touchPolicy, newKeyAlgorithm);

if (TryChangeManagementKey(touchPolicy, newKeyAlgorithm) == false)
Expand Down Expand Up @@ -915,7 +915,7 @@ private bool TryForcedChangeManagementKey(ReadOnlyMemory<byte> currentKey,
return true;
}

_logger.LogInformation($"Failed to set management key. Message: {setResponse.StatusMessage}");
_log.LogInformation($"Failed to set management key. Message: {setResponse.StatusMessage}");

}

Expand Down Expand Up @@ -1058,7 +1058,7 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication,
ManagementKeyAuthenticated = true;
}

_logger.LogInformation($"Failed to authenticate management key. Message: {completeResponse.StatusMessage}");
_log.LogInformation($"Failed to authenticate management key. Message: {completeResponse.StatusMessage}");

return ManagementKeyAuthenticated;
}
Expand Down
10 changes: 5 additions & 5 deletions Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public sealed partial class PivSession : IDisposable
/// </exception>
public T ReadObject<T>() where T : PivDataObject, new()
{
_logger.LogInformation("Read PivObject " + typeof(T) + ".");
_log.LogInformation("Read PivObject " + typeof(T) + ".");
var returnValue = new T();

if (TryReadObject(returnValue))
Expand Down Expand Up @@ -152,7 +152,7 @@ public sealed partial class PivSession : IDisposable
/// </returns>
public bool TryReadObject<T>(out T pivDataObject) where T : PivDataObject, new()
{
_logger.LogInformation("Try to read PivObject " + typeof(T) + ".");
_log.LogInformation("Try to read PivObject " + typeof(T) + ".");
pivDataObject = new T();

return TryReadObject(pivDataObject);
Expand Down Expand Up @@ -207,7 +207,7 @@ public sealed partial class PivSession : IDisposable
/// </exception>
public T ReadObject<T>(int dataTag) where T : PivDataObject, new()
{
_logger.LogInformation("Read PivObject " + typeof(T) + " using dataTag 0x{0:X8}.", dataTag);
_log.LogInformation("Read PivObject " + typeof(T) + " using dataTag 0x{0:X8}.", dataTag);
var returnValue = new T
{
DataTag = dataTag
Expand Down Expand Up @@ -299,7 +299,7 @@ public sealed partial class PivSession : IDisposable
/// </exception>
public bool TryReadObject<T>(int dataTag, out T pivDataObject) where T : PivDataObject, new()
{
_logger.LogInformation("Try to read PivObject " + typeof(T) + ".");
_log.LogInformation("Try to read PivObject " + typeof(T) + ".");
pivDataObject = new T
{
DataTag = dataTag
Expand Down Expand Up @@ -384,7 +384,7 @@ public void WriteObject(PivDataObject pivDataObject)
{
throw new ArgumentNullException(nameof(pivDataObject));
}
_logger.LogInformation("Write PivObject " + pivDataObject.GetType() + " to data tag 0x{0:X8}.");
_log.LogInformation("Write PivObject " + pivDataObject.GetType() + " to data tag 0x{0:X8}.");

byte[] dataToStore = Array.Empty<byte>();

Expand Down
Loading

0 comments on commit 8bb3072

Please sign in to comment.