Skip to content

Commit

Permalink
Merge pull request #205 from WeihanLi/dev
Browse files Browse the repository at this point in the history
1.0.66 preview 1
  • Loading branch information
WeihanLi authored Jun 12, 2024
2 parents a13ce28 + f993424 commit 3ab060a
Show file tree
Hide file tree
Showing 23 changed files with 244 additions and 80 deletions.
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'net6.0'">6.0.0</ExtensionPackageVersion>
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net7.0'">7.0.0</ExtensionPackageVersion>
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</ExtensionPackageVersion>
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0-preview.3.24172.9</ExtensionPackageVersion>
<ExtensionPackageVersion Condition="'$(TargetFramework)' == 'net9.0'">9.0.0-preview.5.24306.7</ExtensionPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(ExtensionPackageVersion)" />
Expand All @@ -17,24 +17,24 @@
<PackageVersion Include="System.Reflection.Emit" Version="4.7.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Serilog" Version="3.1.1" />
<PackageVersion Include="Serilog" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="FluentAssertions" Version="6.6.0" />
<PackageVersion Include="Moq" Version="[4.18.4]" />
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.8" />
<PackageVersion Include="xunit" Version="2.8.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.0" />
<PackageVersion Include="Xunit.DependencyInjection" Version="8.7.1" />
<PackageVersion Include="Xunit.DependencyInjection.Logging" Version="8.1.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.4" />
<PackageVersion Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="Dapper" Version="2.1.44" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions build/build.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2022-2023 Weihan Li. All rights reserved.
// Licensed under the Apache license version 2.0 http://www.apache.org/licenses/LICENSE-2.0

var target = CommandLineParser.ArgValue(args, "target", "Default");
var apiKey = CommandLineParser.ArgValue(args, "apiKey", "");
var stable = CommandLineParser.ArgValue(args, "stable").ToBoolean();
var noPush = CommandLineParser.ArgValue(args, "noPush").ToBoolean();
var target = CommandLineParser.Val("target", "Default", args);
var apiKey = CommandLineParser.Val("apiKey", "", args);
var stable = CommandLineParser.Val("stable", null, args).ToBoolean();
var noPush = CommandLineParser.Val("noPush", null, args).ToBoolean();
var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local");

var solutionPath = "./WeihanLi.Common.sln";
Expand Down
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>65</VersionPatch>
<VersionPatch>66</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
</PropertyGroup>
</Project>
4 changes: 1 addition & 3 deletions src/WeihanLi.Common/Aspect/AttributeInterceptorResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public abstract class AbstractInterceptor : Attribute, IInterceptor
public abstract Task Invoke(IInvocation invocation, Func<Task> next);
}

public sealed class NoIntercept : Attribute
{
}
public sealed class NoIntercept : Attribute;

public class AttributeInterceptorResolver : IInterceptorResolver
{
Expand Down
4 changes: 1 addition & 3 deletions src/WeihanLi.Common/Aspect/InvocationEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace WeihanLi.Common.Aspect;

public interface IInvocationEnricher : IEnricher<IInvocation>
{
}
public interface IInvocationEnricher : IEnricher<IInvocation>;

public sealed class PropertyInvocationEnricher : PropertyEnricher<IInvocation>, IInvocationEnricher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace WeihanLi.Common.DependencyInjection;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public sealed class FromServiceAttribute : Attribute
{
}
public sealed class FromServiceAttribute : Attribute;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace WeihanLi.Common.DependencyInjection;

[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
public sealed class ServiceConstructorAttribute : Attribute
{
}
public sealed class ServiceConstructorAttribute : Attribute;
4 changes: 1 addition & 3 deletions src/WeihanLi.Common/Event/IEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

namespace WeihanLi.Common.Event;

public interface IEventBus : IEventPublisher, IEventSubscriber
{
}
public interface IEventBus : IEventPublisher, IEventSubscriber;
19 changes: 16 additions & 3 deletions src/WeihanLi.Common/Helpers/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Diagnostics.CodeAnalysis;
using System.Text;
using WeihanLi.Extensions;

namespace WeihanLi.Common.Helpers;

Expand Down Expand Up @@ -97,12 +96,26 @@ public static IEnumerable<string> ParseLine(string line, LineParseOptions? optio
/// <param name="defaultValue">default argument value when not found</param>
/// <returns>argument value</returns>
[return: NotNullIfNotNull(nameof(defaultValue))]
[Obsolete("Please use Val instead")]
public static string? ArgValue(string[] args, string argumentName, string? defaultValue = default)
{
return GetArgumentValueInternal(args, argumentName) ?? defaultValue;
return GetOptionValueInternal(args, argumentName) ?? defaultValue;
}

private static string? GetArgumentValueInternal(string[] args, string argumentName)
/// <summary>
/// Get argument value from arguments
/// </summary>
/// <param name="optionName">argument name to get value</param>
/// <param name="defaultValue">default argument value when not found</param>
/// <param name="args">arguments</param>
/// <returns>argument value</returns>
[return: NotNullIfNotNull(nameof(defaultValue))]
public static string? Val(string optionName, string? defaultValue = default, string[]? args = null)
{
return GetOptionValueInternal(args ?? Environment.GetCommandLineArgs(), optionName) ?? defaultValue;
}

private static string? GetOptionValueInternal(string[] args, string argumentName)
{
for (var i = 0; i < args.Length; i++)
{
Expand Down
8 changes: 2 additions & 6 deletions src/WeihanLi.Common/Logging/LogHelperLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ public void Log(LogHelperLogLevel logLevel, Exception? exception, string? messag
}

// ReSharper disable once UnusedTypeParameter
public interface ILogHelperLogger<TCategory> : ILogHelperLogger
{
}
public interface ILogHelperLogger<TCategory> : ILogHelperLogger;

internal sealed class LogHelperGenericLogger<TCategory>(LogHelperFactory logHelperFactory) : LogHelper(logHelperFactory, typeof(TCategory).FullName ?? typeof(TCategory).Name), ILogHelperLogger<TCategory>
{
}
internal sealed class LogHelperGenericLogger<TCategory>(LogHelperFactory logHelperFactory) : LogHelper(logHelperFactory, typeof(TCategory).FullName ?? typeof(TCategory).Name), ILogHelperLogger<TCategory>;

internal class LogHelper(LogHelperFactory logHelperFactory, string categoryName) : ILogHelperLogger
{
Expand Down
4 changes: 1 addition & 3 deletions src/WeihanLi.Common/Logging/LoggingEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace WeihanLi.Common.Logging;

public interface ILogHelperLoggingEnricher : IEnricher<LogHelperLoggingEvent>
{
}
public interface ILogHelperLoggingEnricher : IEnricher<LogHelperLoggingEvent>;

internal sealed class PropertyLoggingEnricher : PropertyEnricher<LogHelperLoggingEvent>, ILogHelperLoggingEnricher
{
Expand Down
25 changes: 14 additions & 11 deletions src/WeihanLi.Common/Logging/MicrosoftLoggingLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ namespace Microsoft.Extensions.Logging;
[ProviderAlias("Delegate")]
public sealed class DelegateLoggerProvider(Action<string, LogLevel, Exception?, string> logAction) : ILoggerProvider
{
private readonly Action<string, LogLevel, Exception?, string> _logAction = logAction;
internal static ILoggerProvider Default { get; } = new DelegateLoggerProvider((category, level, exception, msg) =>
{
Console.WriteLine(@$"[{level}][{category}] {msg}\n{exception}");
});

private readonly ConcurrentDictionary<string, DelegateLogger> _loggers = new();

public void Dispose()
Expand All @@ -20,21 +24,15 @@ public void Dispose()

public ILogger CreateLogger(string categoryName)
{
return _loggers.GetOrAdd(categoryName, category => new DelegateLogger(category, _logAction));
return _loggers.GetOrAdd(categoryName, category => new DelegateLogger(category, logAction));
}

private class DelegateLogger(string categoryName, Action<string, LogLevel, Exception?, string> logAction) : ILogger
private sealed class DelegateLogger(string categoryName, Action<string, LogLevel, Exception?, string> logAction) : ILogger
{
private readonly string _categoryName = categoryName;
private readonly Action<string, LogLevel, Exception?, string> _logAction = logAction;

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (null != _logAction)
{
var msg = formatter(state, exception);
_logAction.Invoke(_categoryName, logLevel, exception, msg);
}
var msg = formatter(state, exception);
logAction.Invoke(categoryName, logLevel, exception, msg);
}

public bool IsEnabled(LogLevel logLevel)
Expand Down Expand Up @@ -132,6 +130,11 @@ public static ILoggerFactory AddDelegateLogger(this ILoggerFactory loggerFactory

#region ILoggingBuilder

public static ILoggingBuilder AddDefaultDelegateLogger(this ILoggingBuilder loggingBuilder)
{
return loggingBuilder.AddProvider(DelegateLoggerProvider.Default);
}

public static ILoggingBuilder AddDelegateLogger(this ILoggingBuilder loggingBuilder,
Action<string, LogLevel, Exception?, string> logAction)
{
Expand Down
Loading

0 comments on commit 3ab060a

Please sign in to comment.