Skip to content

Commit ff72b7d

Browse files
authored
Merge pull request #210 from WeihanLi/dev
1.0.67
2 parents aef1f25 + 12df918 commit ff72b7d

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

Directory.Packages.props

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'net6.0'">6.0.0</ExtensionPackageVersion>
66
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net7.0'">7.0.0</ExtensionPackageVersion>
77
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</ExtensionPackageVersion>
8-
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0-preview.5.24306.7</ExtensionPackageVersion>
8+
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0-preview.6.24327.7</ExtensionPackageVersion>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(ExtensionPackageVersion)" />
@@ -20,20 +20,20 @@
2020
<PackageVersion Include="Serilog" Version="4.0.0" />
2121
</ItemGroup>
2222
<ItemGroup>
23-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
23+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
2424
<PackageVersion Include="FluentAssertions" Version="6.6.0" />
2525
<PackageVersion Include="Moq" Version="[4.18.4]" />
26-
<PackageVersion Include="xunit" Version="2.8.0" />
27-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.0" />
26+
<PackageVersion Include="xunit" Version="2.9.0" />
27+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
2828
<PackageVersion Include="Xunit.DependencyInjection" Version="8.7.1" />
2929
<PackageVersion Include="Xunit.DependencyInjection.Logging" Version="8.1.0" />
3030
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
3131
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
3232
</ItemGroup>
3333
<ItemGroup>
34-
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
35-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.6" />
36-
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
34+
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
35+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.7" />
36+
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.7" />
3737
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
3838
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
3939
<PackageVersion Include="Dapper" Version="2.1.44" />

build/build.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
var target = CommandLineParser.Val("target", "Default", args);
55
var apiKey = CommandLineParser.Val("apiKey", "", args);
6-
var stable = CommandLineParser.Val("stable", null, args).ToBoolean();
7-
var noPush = CommandLineParser.Val("noPush", null, args).ToBoolean();
6+
var stable = CommandLineParser.BooleanVal("stable", false, args);
7+
var noPush = CommandLineParser.BooleanVal("noPush", false, args);
88
var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local");
99

1010
var solutionPath = "./WeihanLi.Common.sln";

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>1</VersionMajor>
44
<VersionMinor>0</VersionMinor>
5-
<VersionPatch>66</VersionPatch>
5+
<VersionPatch>67</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

src/WeihanLi.Common/Helpers/CommandLineParser.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using System.Text;
6+
using WeihanLi.Extensions;
67

78
namespace WeihanLi.Common.Helpers;
89

@@ -91,28 +92,26 @@ public static IEnumerable<string> ParseLine(string line, LineParseOptions? optio
9192
/// <summary>
9293
/// Get argument value from arguments
9394
/// </summary>
94-
/// <param name="args">arguments</param>
95-
/// <param name="argumentName">argument name to get value</param>
95+
/// <param name="optionName">argument name to get value</param>
9696
/// <param name="defaultValue">default argument value when not found</param>
97+
/// <param name="args">arguments</param>
9798
/// <returns>argument value</returns>
9899
[return: NotNullIfNotNull(nameof(defaultValue))]
99-
[Obsolete("Please use Val instead")]
100-
public static string? ArgValue(string[] args, string argumentName, string? defaultValue = default)
100+
public static string? Val(string optionName, string? defaultValue = default, string[]? args = null)
101101
{
102-
return GetOptionValueInternal(args, argumentName) ?? defaultValue;
102+
return GetOptionValueInternal(args ?? Environment.GetCommandLineArgs(), optionName) ?? defaultValue;
103103
}
104104

105105
/// <summary>
106-
/// Get argument value from arguments
106+
/// Get boolean argument value from arguments
107107
/// </summary>
108108
/// <param name="optionName">argument name to get value</param>
109109
/// <param name="defaultValue">default argument value when not found</param>
110110
/// <param name="args">arguments</param>
111111
/// <returns>argument value</returns>
112-
[return: NotNullIfNotNull(nameof(defaultValue))]
113-
public static string? Val(string optionName, string? defaultValue = default, string[]? args = null)
112+
public static bool BooleanVal(string optionName, bool defaultValue = default, string[]? args = null)
114113
{
115-
return GetOptionValueInternal(args ?? Environment.GetCommandLineArgs(), optionName) ?? defaultValue;
114+
return GetOptionValueInternal(args ?? Environment.GetCommandLineArgs(), optionName).ToBoolean(defaultValue);
116115
}
117116

118117
private static string? GetOptionValueInternal(string[] args, string argumentName)

src/WeihanLi.Common/Logging/MicrosoftLoggingLoggerExtensions.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using System.Collections.Concurrent;
3+
using System.Diagnostics;
34
using WeihanLi.Common;
5+
using WeihanLi.Common.Helpers;
46
using WeihanLi.Common.Logging;
57
using WeihanLi.Common.Services;
68

@@ -12,7 +14,45 @@ public sealed class DelegateLoggerProvider(Action<string, LogLevel, Exception?,
1214
{
1315
internal static ILoggerProvider Default { get; } = new DelegateLoggerProvider((category, level, exception, msg) =>
1416
{
15-
Console.WriteLine(@$"[{level}][{category}] {msg}\n{exception}");
17+
var (foregroundColor, backgroundColor) = GetConsoleColorForLogLevel(level);
18+
var levelText = GetLogLevelText(level);
19+
var dateTime = DateTimeOffset.Now;
20+
var message = @$"[{levelText}][{category}] {dateTime} {msg}";
21+
if (exception is not null)
22+
{
23+
message = $"{message}{Environment.NewLine}{exception}";
24+
}
25+
26+
ConsoleHelper.WriteLineWithColor(message, foregroundColor, backgroundColor);
27+
if (level is LogLevel.Trace)
28+
{
29+
Trace.WriteLine(message);
30+
}
31+
32+
return;
33+
34+
static (ConsoleColor? ForegroundColor, ConsoleColor? BackgroundColor) GetConsoleColorForLogLevel(LogLevel logLevel)
35+
=> logLevel switch
36+
{
37+
LogLevel.Trace or LogLevel.Debug => (ConsoleColor.DarkGray, ConsoleColor.Black),
38+
LogLevel.Information => (ConsoleColor.DarkGreen, ConsoleColor.Black),
39+
LogLevel.Warning => (ConsoleColor.Yellow, ConsoleColor.Black),
40+
LogLevel.Error => (ConsoleColor.Black, ConsoleColor.DarkRed),
41+
LogLevel.Critical => (ConsoleColor.White, ConsoleColor.DarkRed),
42+
_ => (null, null)
43+
};
44+
45+
static string GetLogLevelText(LogLevel logLevel)
46+
=> logLevel switch
47+
{
48+
LogLevel.Trace => "trce",
49+
LogLevel.Debug => "dbug",
50+
LogLevel.Information => "info",
51+
LogLevel.Warning => "warn",
52+
LogLevel.Error => "fail",
53+
LogLevel.Critical => "crit",
54+
_ => logLevel.ToString().ToLowerInvariant()
55+
};
1656
});
1757

1858
private readonly ConcurrentDictionary<string, DelegateLogger> _loggers = new();
@@ -35,20 +75,14 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3575
logAction.Invoke(categoryName, logLevel, exception, msg);
3676
}
3777

38-
public bool IsEnabled(LogLevel logLevel)
39-
{
40-
return true;
41-
}
78+
public bool IsEnabled(LogLevel logLevel) => true;
4279

4380
#if NET7_0_OR_GREATER
4481
IDisposable?
4582
#else
4683
IDisposable
4784
#endif
48-
ILogger.BeginScope<TState>(TState state)
49-
{
50-
return NullScope.Instance;
51-
}
85+
ILogger.BeginScope<TState>(TState state) => NullScope.Instance;
5286
}
5387
}
5488

0 commit comments

Comments
 (0)