Removes dependency on Microsoft.Extensions.Logging

This commit is contained in:
Ryan Newington
2023-07-22 14:44:23 +10:00
parent dc76336ce3
commit ed679eba6b
20 changed files with 77 additions and 23 deletions
@@ -3,8 +3,6 @@ using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Lithnet.CredentialProvider
{
@@ -19,8 +17,7 @@ namespace Lithnet.CredentialProvider
private FieldInteractiveState interactiveState;
private string label;
private FieldOptions options;
private protected ILogger logger = NullLogger.Instance;
private protected ILogger logger;
public event PropertyChangedEventHandler PropertyChanged;
private protected ControlBase(ControlBase source)
@@ -52,7 +49,7 @@ namespace Lithnet.CredentialProvider
this.state = FieldState.DisplayInSelectedTile;
this.interactiveState = FieldInteractiveState.None;
this.options = FieldOptions.None;
this.logger = TraceLoggerFactory.Instance.CreateLogger(this.GetType());
this.Key = key;
}
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -2,7 +2,6 @@
using System.Linq;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,6 +1,5 @@
using System;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Lithnet.CredentialProvider
{
@@ -73,7 +71,7 @@ namespace Lithnet.CredentialProvider
/// Gets a logger factory. Override this method and provide an implementation of <c ref="ILoggerFactory"/> to enable credential provider logging
/// </summary>
/// <returns>An ILoggerFactory instance</returns>
protected virtual ILoggerFactory GetLoggerFactory() { return NullLoggerFactory.Instance; }
protected virtual ILoggerFactory GetLoggerFactory() { return TraceLoggerFactory.Instance; }
/// <summary>
/// Gets a value indicating if the credential provider supports the <c ref="UsageScenario"/> provided by LogonUI or CredUI
@@ -128,7 +126,7 @@ namespace Lithnet.CredentialProvider
/// <summary>
/// Removes one or more user tiles, and notifies LogonUI that tiles have been removed
/// </summary>
/// <param name="tiles">The crendential tiles to remove</param>
/// <param name="tiles">The credential tiles to remove</param>
public void RemoveUserTiles(params CredentialTile[] tiles)
{
if (tiles == null)
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,6 +1,5 @@
using System;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,6 +1,5 @@
using System;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,6 +1,5 @@
using System;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -1,6 +1,5 @@
using System;
using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider
{
@@ -2,7 +2,6 @@
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider.Interop
{
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Security;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider.Interop
{
@@ -39,7 +39,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.32" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -0,0 +1,12 @@
using System;
namespace Lithnet.CredentialProvider
{
public interface ILogger
{
void LogError(Exception ex, string v);
void LogError(string v);
void LogTrace(string v);
void LogWarning(string message);
}
}
@@ -0,0 +1,11 @@
using System;
namespace Lithnet.CredentialProvider
{
public interface ILoggerFactory
{
ILogger CreateLogger(Type type);
ILogger CreateLogger<T>();
}
}
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics;
namespace Lithnet.CredentialProvider
{
public class TraceLogger : ILogger
{
public void LogError(Exception ex, string v)
{
Trace.TraceError(v + "\r\n\r\n" + ex?.ToString());
}
public void LogError(string v)
{
Trace.TraceError(v);
}
public void LogTrace(string v)
{
Trace.TraceInformation(v);
}
public void LogWarning(string message)
{
Trace.TraceWarning(message);
}
}
}
@@ -0,0 +1,21 @@
using System;
namespace Lithnet.CredentialProvider
{
public class TraceLoggerFactory : ILoggerFactory
{
public ILogger CreateLogger(Type type)
{
return new TraceLogger();
}
public ILogger CreateLogger<T>()
{
return new TraceLogger();
}
private static readonly TraceLoggerFactory loggerFactory = new TraceLoggerFactory();
public static ILoggerFactory Instance => loggerFactory;
}
}