-
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1114 from jnyrup/logging
Extract dependency on MELA to own package
- Loading branch information
Showing
14 changed files
with
100 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>10.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- Should reference the first version of FluentFTP that exposes IFluentFtpLogger --> | ||
<!--<PackageReference Include="FluentFTP" Version="42.2.0" />--> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- this is just to make it compile, FluentFTP should be referenced through a <PackageReference> --> | ||
<ProjectReference Include="..\FluentFTP\FluentFTP.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace FluentFTP.Logging { | ||
public sealed class MicrosoftLoggingAdapter : IFluentLogger { | ||
private readonly ILogger adaptee; | ||
|
||
public MicrosoftLoggingAdapter(ILogger adaptee) => | ||
this.adaptee = adaptee; | ||
|
||
public void Log(LogEntry entry) => | ||
adaptee.Log(ToLevel(entry.Severity), 0, entry.Message, entry.Exception, (s, _) => s); | ||
|
||
private static LogLevel ToLevel(FtpTraceLevel s) => s switch { | ||
FtpTraceLevel.Verbose => LogLevel.Debug, | ||
FtpTraceLevel.Info => LogLevel.Information, | ||
FtpTraceLevel.Warn => LogLevel.Warning, | ||
FtpTraceLevel.Error => LogLevel.Error, | ||
_ => LogLevel.Information | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace FluentFTP.Logging { | ||
public interface IFluentLogger { | ||
void Log(LogEntry entry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace FluentFTP.Logging { | ||
public readonly struct LogEntry { | ||
public FtpTraceLevel Severity { get; } | ||
public string Message { get; } | ||
public Exception Exception { get; } | ||
|
||
public LogEntry(FtpTraceLevel severity, string msg, Exception ex = null) { | ||
Severity = severity; | ||
Message = msg; | ||
Exception = ex; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace FluentFTP.Logging { | ||
public static class LoggerExtensions { | ||
public static void Log(this IFluentLogger logger, FtpTraceLevel eventType, string message, Exception ex = null) => | ||
logger.Log(new LogEntry(eventType, message, ex)); | ||
} | ||
} |