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
+1 -1
View File
@@ -13,7 +13,7 @@ variables:
- name: build.version.revision - name: build.version.revision
value: $[counter(format('{0}.{1}', variables['build.version.major'], variables['build.version.minor']), 0)] value: $[counter(format('{0}.{1}', variables['build.version.major'], variables['build.version.minor']), 0)]
- name: build.version.suffix - name: build.version.suffix
value: -beta1 value:
- name: build.version - name: build.version
value: $(build.version.major).$(build.version.minor).$(build.version.revision)$(build.version.suffix) value: $(build.version.major).$(build.version.minor).$(build.version.revision)$(build.version.suffix)
- name: build.versionShort - name: build.versionShort
@@ -3,8 +3,6 @@ using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -19,8 +17,7 @@ namespace Lithnet.CredentialProvider
private FieldInteractiveState interactiveState; private FieldInteractiveState interactiveState;
private string label; private string label;
private FieldOptions options; private FieldOptions options;
private protected ILogger logger = NullLogger.Instance; private protected ILogger logger;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
private protected ControlBase(ControlBase source) private protected ControlBase(ControlBase source)
@@ -52,7 +49,7 @@ namespace Lithnet.CredentialProvider
this.state = FieldState.DisplayInSelectedTile; this.state = FieldState.DisplayInSelectedTile;
this.interactiveState = FieldInteractiveState.None; this.interactiveState = FieldInteractiveState.None;
this.options = FieldOptions.None; this.options = FieldOptions.None;
this.logger = TraceLoggerFactory.Instance.CreateLogger(this.GetType());
this.Key = key; this.Key = key;
} }
@@ -1,7 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,6 +1,5 @@
using System; using System;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Lithnet.CredentialProvider 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 /// Gets a logger factory. Override this method and provide an implementation of <c ref="ILoggerFactory"/> to enable credential provider logging
/// </summary> /// </summary>
/// <returns>An ILoggerFactory instance</returns> /// <returns>An ILoggerFactory instance</returns>
protected virtual ILoggerFactory GetLoggerFactory() { return NullLoggerFactory.Instance; } protected virtual ILoggerFactory GetLoggerFactory() { return TraceLoggerFactory.Instance; }
/// <summary> /// <summary>
/// Gets a value indicating if the credential provider supports the <c ref="UsageScenario"/> provided by LogonUI or CredUI /// 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> /// <summary>
/// Removes one or more user tiles, and notifies LogonUI that tiles have been removed /// Removes one or more user tiles, and notifies LogonUI that tiles have been removed
/// </summary> /// </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) public void RemoveUserTiles(params CredentialTile[] tiles)
{ {
if (tiles == null) if (tiles == null)
@@ -1,7 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,7 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,6 +1,5 @@
using System; using System;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,7 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,6 +1,5 @@
using System; using System;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,6 +1,5 @@
using System; using System;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -1,6 +1,5 @@
using System; using System;
using Lithnet.CredentialProvider.Interop; using Lithnet.CredentialProvider.Interop;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider namespace Lithnet.CredentialProvider
{ {
@@ -2,7 +2,6 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Text; using System.Text;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider.Interop namespace Lithnet.CredentialProvider.Interop
{ {
@@ -1,7 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Security; using System.Security;
using Microsoft.Extensions.Logging;
namespace Lithnet.CredentialProvider.Interop namespace Lithnet.CredentialProvider.Interop
{ {
@@ -39,7 +39,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.32" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1"> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <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;
}
}