Invert coupling from Core to Logging

This commit is contained in:
Matt Nadareski
2024-07-17 16:01:22 -04:00
parent 5ca6da14fb
commit 0b84b85ba8
7 changed files with 45 additions and 36 deletions

View File

@@ -24,6 +24,10 @@
<InternalsVisibleTo Include="SabreTools.Test" /> <InternalsVisibleTo Include="SabreTools.Test" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreTools.Logging\SabreTools.Logging.csproj" />
</ItemGroup>
<!-- Support for old .NET versions --> <!-- Support for old .NET versions -->
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`))"> <ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`))">
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" /> <PackageReference Include="Net30.LinqBridge" Version="1.3.0" />

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using SabreTools.Logging;
namespace SabreTools.Core.Tools namespace SabreTools.Core.Tools
{ {
@@ -8,6 +9,23 @@ namespace SabreTools.Core.Tools
{ {
#region String to Enum #region String to Enum
/// <summary>
/// Get the LogLevel value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns></returns>
public static LogLevel AsLogLevel(this string? value)
{
return value?.ToLowerInvariant() switch
{
"verbose" => LogLevel.VERBOSE,
"user" => LogLevel.USER,
"warning" => LogLevel.WARNING,
"error" => LogLevel.ERROR,
_ => LogLevel.VERBOSE,
};
}
/// <summary> /// <summary>
/// Get bool? value from input string /// Get bool? value from input string
/// </summary> /// </summary>

View File

@@ -1,22 +1,13 @@
using SabreTools.Core; namespace SabreTools.Logging
namespace SabreTools.Logging
{ {
/// <summary> /// <summary>
/// Severity of the logging statement /// Severity of the logging statement
/// </summary> /// </summary>
public enum LogLevel public enum LogLevel
{ {
[Mapping("verbose")]
VERBOSE = 0, VERBOSE = 0,
[Mapping("user")]
USER, USER,
[Mapping("warning")]
WARNING, WARNING,
[Mapping("error")]
ERROR, ERROR,
} }
} }

View File

@@ -42,9 +42,9 @@ namespace SabreTools.Logging
/// </summary> /// </summary>
public LogEventArgs(LogLevel logLevel = LogLevel.VERBOSE, string? statement = null, Exception? exception = null) public LogEventArgs(LogLevel logLevel = LogLevel.VERBOSE, string? statement = null, Exception? exception = null)
{ {
this.LogLevel = logLevel; LogLevel = logLevel;
this.Statement = statement; Statement = statement;
this.Exception = exception; Exception = exception;
} }
/// <summary> /// <summary>
@@ -52,10 +52,10 @@ namespace SabreTools.Logging
/// </summary> /// </summary>
public LogEventArgs(long total, long current, LogLevel logLevel = LogLevel.VERBOSE, string? statement = null) public LogEventArgs(long total, long current, LogLevel logLevel = LogLevel.VERBOSE, string? statement = null)
{ {
this.LogLevel = logLevel; LogLevel = logLevel;
this.Statement = statement; Statement = statement;
this.TotalCount = total; TotalCount = total;
this.CurrentCount = current; CurrentCount = current;
} }
} }
} }

View File

@@ -11,14 +11,14 @@ namespace SabreTools.Logging
/// Instance associated with this logger /// Instance associated with this logger
/// </summary> /// </summary>
/// TODO: Derive class name for this object, if possible /// TODO: Derive class name for this object, if possible
private readonly object? instance; private readonly object? _instance;
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
public Logger(object? instance = null) public Logger(object? instance = null)
{ {
this.instance = instance; _instance = instance;
} }
#region Log Event Triggers #region Log Event Triggers
@@ -31,7 +31,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Verbose(Exception ex, string? output = null) public void Verbose(Exception ex, string? output = null)
{ {
LoggerImpl.Verbose(this.instance, ex, output); LoggerImpl.Verbose(_instance, ex, output);
} }
/// <summary> /// <summary>
@@ -41,7 +41,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Verbose(string output) public void Verbose(string output)
{ {
LoggerImpl.Verbose(this.instance, output); LoggerImpl.Verbose(_instance, output);
} }
/// <summary> /// <summary>
@@ -52,7 +52,7 @@ namespace SabreTools.Logging
/// <param name="output">String to be written log</param> /// <param name="output">String to be written log</param>
public void Verbose(long total, long current, string? output = null) public void Verbose(long total, long current, string? output = null)
{ {
LoggerImpl.Verbose(instance, total, current, output); LoggerImpl.Verbose(_instance, total, current, output);
} }
/// <summary> /// <summary>
@@ -63,7 +63,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void User(Exception ex, string? output = null) public void User(Exception ex, string? output = null)
{ {
LoggerImpl.User(this.instance, ex, output); LoggerImpl.User(_instance, ex, output);
} }
/// <summary> /// <summary>
@@ -73,7 +73,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void User(string output) public void User(string output)
{ {
LoggerImpl.User(this.instance, output); LoggerImpl.User(_instance, output);
} }
/// <summary> /// <summary>
@@ -84,7 +84,7 @@ namespace SabreTools.Logging
/// <param name="output">String to be written log</param> /// <param name="output">String to be written log</param>
public void User(long total, long current, string? output = null) public void User(long total, long current, string? output = null)
{ {
LoggerImpl.User(instance, total, current, output); LoggerImpl.User(_instance, total, current, output);
} }
/// <summary> /// <summary>
@@ -95,7 +95,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Warning(Exception ex, string? output = null) public void Warning(Exception ex, string? output = null)
{ {
LoggerImpl.Warning(this.instance, ex, output); LoggerImpl.Warning(_instance, ex, output);
} }
/// <summary> /// <summary>
@@ -105,7 +105,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Warning(string output) public void Warning(string output)
{ {
LoggerImpl.Warning(this.instance, output); LoggerImpl.Warning(_instance, output);
} }
/// <summary> /// <summary>
@@ -116,7 +116,7 @@ namespace SabreTools.Logging
/// <param name="output">String to be written log</param> /// <param name="output">String to be written log</param>
public void Warning(long total, long current, string? output = null) public void Warning(long total, long current, string? output = null)
{ {
LoggerImpl.Warning(instance, total, current, output); LoggerImpl.Warning(_instance, total, current, output);
} }
/// <summary> /// <summary>
@@ -127,7 +127,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Error(Exception ex, string? output = null) public void Error(Exception ex, string? output = null)
{ {
LoggerImpl.Error(this.instance, ex, output); LoggerImpl.Error(_instance, ex, output);
} }
/// <summary> /// <summary>
@@ -137,7 +137,7 @@ namespace SabreTools.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public void Error(string output) public void Error(string output)
{ {
LoggerImpl.Error(this.instance, output); LoggerImpl.Error(_instance, output);
} }
/// <summary> /// <summary>
@@ -148,7 +148,7 @@ namespace SabreTools.Logging
/// <param name="output">String to be written log</param> /// <param name="output">String to be written log</param>
public void Error(long total, long current, string? output = null) public void Error(long total, long current, string? output = null)
{ {
LoggerImpl.Error(instance, total, current, output); LoggerImpl.Error(_instance, total, current, output);
} }
#endregion #endregion

View File

@@ -20,10 +20,6 @@
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SabreTools.Core\SabreTools.Core.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SabreTools.IO" Version="1.4.11" /> <PackageReference Include="SabreTools.IO" Version="1.4.11" />
</ItemGroup> </ItemGroup>

View File

@@ -1894,7 +1894,7 @@ Some special strings that can be used:
Extras = GetExtras(features); Extras = GetExtras(features);
FilterRunner = GetFilterRunner(features); FilterRunner = GetFilterRunner(features);
Header = GetDatHeader(features); Header = GetDatHeader(features);
LogLevel = GetString(features, LogLevelStringValue).AsEnumValue<LogLevel>(); LogLevel = GetString(features, LogLevelStringValue).AsLogLevel();
OutputDir = GetString(features, OutputDirStringValue)?.Trim('"'); OutputDir = GetString(features, OutputDirStringValue)?.Trim('"');
Remover = GetRemover(features); Remover = GetRemover(features);
ScriptMode = GetBoolean(features, ScriptValue); ScriptMode = GetBoolean(features, ScriptValue);