From b1044107cfdee815f28df08c19cc79dec4a9b2c0 Mon Sep 17 00:00:00 2001
From: root <8907060@qq.com>
Date: Fri, 10 Nov 2023 09:38:05 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Exceptionless=20=E6=97=A5?=
=?UTF-8?q?=E5=BF=97=E9=85=8D=E7=BD=AE=E6=96=B9=E6=B3=95=E4=B8=BA=20AddExc?=
=?UTF-8?q?eptionless?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build/version.props | 2 +-
src/Util.Data.Abstractions/Stores/IStore.cs | 4 +-
src/Util.Data.Dapper.Core/Sql/SqlQueryBase.cs | 8 +--
.../OracleDapperServiceRegistrar.cs | 35 -------------
.../ServiceRegistrarConfigExtensions.cs | 26 ----------
.../Sql/AppBuilderExtensions.cs | 12 +++++
.../AppBuilderExtensions.cs | 51 ++++++++++++++++---
.../SerilogExceptionlessConfiguration.cs | 25 ---------
.../SqlExecutor/MySqlExecutorTest.Execute.cs | 22 ++++++++
.../Startup.cs | 2 +-
.../appsettings.json | 4 +-
test/Util.TestShare/Models/Product.cs | 7 +++
12 files changed, 95 insertions(+), 103 deletions(-)
delete mode 100644 src/Util.Data.Dapper.Oracle/Infrastructure/OracleDapperServiceRegistrar.cs
delete mode 100644 src/Util.Data.Dapper.Oracle/Infrastructure/ServiceRegistrarConfigExtensions.cs
delete mode 100644 src/Util.Logging.Serilog.Exceptionless/SerilogExceptionlessConfiguration.cs
diff --git a/build/version.props b/build/version.props
index a1831e13..76cfa14a 100644
--- a/build/version.props
+++ b/build/version.props
@@ -2,7 +2,7 @@
7
1
- 70
+ 73
$(VersionMajor).$(VersionMinor).$(VersionPatch)
diff --git a/src/Util.Data.Abstractions/Stores/IStore.cs b/src/Util.Data.Abstractions/Stores/IStore.cs
index 3b201080..2a0c4ee5 100644
--- a/src/Util.Data.Abstractions/Stores/IStore.cs
+++ b/src/Util.Data.Abstractions/Stores/IStore.cs
@@ -1,6 +1,4 @@
-using Util.Aop;
-using Util.Domain;
-using Util.Validation;
+using Util.Domain;
namespace Util.Data.Stores;
diff --git a/src/Util.Data.Dapper.Core/Sql/SqlQueryBase.cs b/src/Util.Data.Dapper.Core/Sql/SqlQueryBase.cs
index 9a2e3870..12f7b1d9 100644
--- a/src/Util.Data.Dapper.Core/Sql/SqlQueryBase.cs
+++ b/src/Util.Data.Dapper.Core/Sql/SqlQueryBase.cs
@@ -1347,11 +1347,11 @@ public abstract class SqlQueryBase : ISqlQuery, ISqlPartAccessor, ISqlOptionsAcc
if ( Logger.IsEnabled( LogLevel.Trace ) == false )
return;
var message = new StringBuilder();
- message.AppendLine( "标题: {Caption}" );
+ message.AppendLine( "标题: Sql日志" );
message.AppendLine( "原始Sql:" );
- message.AppendLine( "{Sql}" );
+ message.AppendLine( PreviousSql.GetSql() );
message.AppendLine( "调试Sql:" );
- message.AppendLine( "{DebugSql}" );
+ message.AppendLine( PreviousSql.GetDebugSql() );
message.AppendLine( "Sql参数:" );
foreach ( var param in PreviousSql.GetParams() ) {
message.Append( "参数名: " );
@@ -1382,7 +1382,7 @@ public abstract class SqlQueryBase : ISqlQuery, ISqlPartAccessor, ISqlOptionsAcc
}
message.AppendLine();
}
- Logger.LogTrace( message.ToString(), "Sql日志", PreviousSql.GetSql(), PreviousSql.GetDebugSql() );
+ Logger.LogTrace( message.ToString() );
}
#endregion
diff --git a/src/Util.Data.Dapper.Oracle/Infrastructure/OracleDapperServiceRegistrar.cs b/src/Util.Data.Dapper.Oracle/Infrastructure/OracleDapperServiceRegistrar.cs
deleted file mode 100644
index 4499df56..00000000
--- a/src/Util.Data.Dapper.Oracle/Infrastructure/OracleDapperServiceRegistrar.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Util.Data.Dapper.TypeHandlers;
-using Util.Infrastructure;
-
-namespace Util.Data.Dapper.Infrastructure;
-
-///
-/// Oracle Dapper服务注册器
-///
-public class OracleDapperServiceRegistrar : IServiceRegistrar {
- ///
- /// 获取服务名
- ///
- public static string ServiceName => "Util.Data.Dapper.Infrastructure.OracleDapperServiceRegistrar";
-
- ///
- /// 排序号
- ///
- public int OrderId => 812;
-
- ///
- /// 是否启用
- ///
- public bool Enabled => ServiceRegistrarConfig.IsEnabled( ServiceName );
-
- ///
- /// 注册服务
- ///
- /// 服务上下文
- public Action Register( ServiceContext serviceContext ) {
- SqlMapper.RemoveTypeMap( typeof( Guid ) );
- SqlMapper.RemoveTypeMap( typeof( Guid? ) );
- SqlMapper.AddTypeHandler( typeof( Guid ), new GuidTypeHandler() );
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/Util.Data.Dapper.Oracle/Infrastructure/ServiceRegistrarConfigExtensions.cs b/src/Util.Data.Dapper.Oracle/Infrastructure/ServiceRegistrarConfigExtensions.cs
deleted file mode 100644
index 515a428d..00000000
--- a/src/Util.Data.Dapper.Oracle/Infrastructure/ServiceRegistrarConfigExtensions.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Util.Infrastructure;
-
-namespace Util.Data.Dapper.Infrastructure;
-
-///
-/// Oracle Dapper服务注册器配置扩展
-///
-public static class ServiceRegistrarConfigExtensions {
- ///
- /// 启用Oracle Dapper服务注册器
- ///
- /// 服务注册器配置
- public static ServiceRegistrarConfig EnableOracleDapperServiceRegistrar( this ServiceRegistrarConfig config ) {
- ServiceRegistrarConfig.Enable( OracleDapperServiceRegistrar.ServiceName );
- return config;
- }
-
- ///
- ///禁用Oracle Dapper服务注册器
- ///
- /// 服务注册器配置
- public static ServiceRegistrarConfig DisableOracleDapperServiceRegistrar( this ServiceRegistrarConfig config ) {
- ServiceRegistrarConfig.Disable( OracleDapperServiceRegistrar.ServiceName );
- return config;
- }
-}
\ No newline at end of file
diff --git a/src/Util.Data.Dapper.Oracle/Sql/AppBuilderExtensions.cs b/src/Util.Data.Dapper.Oracle/Sql/AppBuilderExtensions.cs
index 42595f06..a9a45258 100644
--- a/src/Util.Data.Dapper.Oracle/Sql/AppBuilderExtensions.cs
+++ b/src/Util.Data.Dapper.Oracle/Sql/AppBuilderExtensions.cs
@@ -1,4 +1,5 @@
using Util.Configs;
+using Util.Data.Dapper.TypeHandlers;
using Util.Data.Sql;
namespace Util.Data.Dapper.Sql;
@@ -61,10 +62,20 @@ public static class AppBuilderExtensions {
builder.Host.ConfigureServices( ( context, services ) => {
services.TryAddTransient( typeof( TService ), typeof( TImplementation ) );
services.TryAddSingleton( typeof( SqlOptions ), ( sp ) => options );
+ RegisterGuidTypeHandler();
} );
return builder;
}
+ ///
+ /// 注册Guid类型处理器
+ ///
+ private static void RegisterGuidTypeHandler() {
+ SqlMapper.RemoveTypeMap( typeof( Guid ) );
+ SqlMapper.RemoveTypeMap( typeof( Guid? ) );
+ SqlMapper.AddTypeHandler( typeof( Guid ), new GuidTypeHandler() );
+ }
+
#endregion
#region AddOracleSqlExecutor(配置Oracle Sql执行器)
@@ -119,6 +130,7 @@ public static class AppBuilderExtensions {
builder.Host.ConfigureServices( ( context, services ) => {
services.TryAddTransient( typeof( TService ), typeof( TImplementation ) );
services.TryAddSingleton( typeof( SqlOptions ), ( sp ) => options );
+ RegisterGuidTypeHandler();
} );
return builder;
}
diff --git a/src/Util.Logging.Serilog.Exceptionless/AppBuilderExtensions.cs b/src/Util.Logging.Serilog.Exceptionless/AppBuilderExtensions.cs
index 25f1a993..7087ef46 100644
--- a/src/Util.Logging.Serilog.Exceptionless/AppBuilderExtensions.cs
+++ b/src/Util.Logging.Serilog.Exceptionless/AppBuilderExtensions.cs
@@ -8,25 +8,64 @@ namespace Util.Logging.Serilog;
///
public static class AppBuilderExtensions {
///
- /// 配置Serilog日志操作
+ /// 配置Exceptionless日志操作
+ ///
+ /// 应用生成器
+ /// 是否清除默认设置的日志提供程序
+ public static IAppBuilder AddExceptionless( this IAppBuilder builder, bool isClearProviders = false ) {
+ return builder.AddExceptionless( null, isClearProviders );
+ }
+
+ ///
+ /// 配置Exceptionless日志操作
+ ///
+ /// 应用生成器
+ /// 应用程序名称
+ public static IAppBuilder AddExceptionless( this IAppBuilder builder, string appName ) {
+ return builder.AddExceptionless( null, appName );
+ }
+
+ ///
+ /// 配置Exceptionless日志操作
///
/// 应用生成器
/// Exceptionless日志配置操作
/// 是否清除默认设置的日志提供程序
- public static IAppBuilder AddSerilog( this IAppBuilder builder, Action configAction, bool isClearProviders = false ) {
+ public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action configAction, bool isClearProviders = false ) {
+ return builder.AddExceptionless( configAction, t => t.IsClearProviders = isClearProviders );
+ }
+
+ ///
+ /// 配置Exceptionless日志操作
+ ///
+ /// 应用生成器
+ /// Exceptionless日志配置操作
+ /// 应用程序名称
+ public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action configAction, string appName ) {
+ return builder.AddExceptionless( configAction, t => t.Application = appName );
+ }
+
+ ///
+ /// 配置Exceptionless日志操作
+ ///
+ /// 应用生成器
+ /// Exceptionless日志配置操作
+ /// 日志配置
+ public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action configAction, Action setupAction ) {
builder.CheckNull( nameof( builder ) );
+ var options = new LogOptions();
+ setupAction?.Invoke( options );
builder.Host.ConfigureServices( ( context, services ) => {
- var config = new SerilogExceptionlessConfiguration();
- configAction( config );
services.AddSingleton();
services.AddTransient( typeof( ILog<> ), typeof( Log<> ) );
services.AddTransient( typeof( ILog ), t => t.GetService()?.CreateLog( "default" ) ?? NullLog.Instance );
var configuration = context.Configuration;
services.AddLogging( loggingBuilder => {
- if ( isClearProviders )
+ if ( options.IsClearProviders )
loggingBuilder.ClearProviders();
- ConfigExceptionless( config.ConfigAction, configuration );
+ ConfigExceptionless( configAction, configuration );
SerilogLog.Logger = new LoggerConfiguration()
+ .Enrich.WithProperty( "Application", options.Application )
.Enrich.FromLogContext()
.Enrich.WithLogLevel()
.Enrich.WithLogContext()
diff --git a/src/Util.Logging.Serilog.Exceptionless/SerilogExceptionlessConfiguration.cs b/src/Util.Logging.Serilog.Exceptionless/SerilogExceptionlessConfiguration.cs
deleted file mode 100644
index ddba0703..00000000
--- a/src/Util.Logging.Serilog.Exceptionless/SerilogExceptionlessConfiguration.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace Util.Logging.Serilog;
-
-///
-/// Serilog Exceptionless日志配置
-///
-public class SerilogExceptionlessConfiguration {
- ///
- /// 添加Exceptionless日志组件
- ///
- public void AddExceptionless() {
- }
-
- ///
- /// 添加Exceptionless日志组件
- ///
- /// Exceptionless日志配置操作
- public void AddExceptionless( Action configAction ) {
- ConfigAction = configAction;
- }
-
- ///
- /// Exceptionless日志配置操作
- ///
- internal Action ConfigAction { get; private set; }
-}
\ No newline at end of file
diff --git a/test/Util.Data.Dapper.MySql.Tests.Integration/SqlExecutor/MySqlExecutorTest.Execute.cs b/test/Util.Data.Dapper.MySql.Tests.Integration/SqlExecutor/MySqlExecutorTest.Execute.cs
index 084455e4..c283a48c 100644
--- a/test/Util.Data.Dapper.MySql.Tests.Integration/SqlExecutor/MySqlExecutorTest.Execute.cs
+++ b/test/Util.Data.Dapper.MySql.Tests.Integration/SqlExecutor/MySqlExecutorTest.Execute.cs
@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Util.Data.Sql;
using Util.Tests.Configs;
+using Util.Tests.Models;
using Xunit;
namespace Util.Data.Dapper.Tests.SqlExecutor {
@@ -24,5 +25,26 @@ namespace Util.Data.Dapper.Tests.SqlExecutor {
var result = await _sqlExecutor.Select( "Code" ).From( "Product" ).Where( "ProductId", id ).ToStringAsync();
Assert.Equal( TestConfig.Value, result );
}
+
+ ///
+ /// 测试执行Sql增删改操作 - 写入扩展属性
+ ///
+ [Fact]
+ public async Task TestExecuteAsync_2() {
+ var id = Guid.NewGuid();
+ var product = new Product( id ) {
+ Code = TestConfig.Value,
+ TestProperty1 = "a"
+ };
+ await _sqlExecutor
+ .AppendLine( "Insert Product(ProductId,Code,ExtraProperties) " )
+ .Append( "Values(@Id,@Code,@ExtraProperties)" )
+ .AddDynamicParams( product )
+ .AddParam( "ExtraProperties", product.GetExtraPropertiesJson() )
+ .ExecuteAsync();
+ var result = await _sqlExecutor.Select( "*" ).From( "Product" ).Where( "ProductId", id ).ExecuteSingleAsync();
+ Assert.Equal( TestConfig.Value, result.Code );
+ Assert.Equal( "a", result.TestProperty1 );
+ }
}
}
diff --git a/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/Startup.cs b/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/Startup.cs
index a18f1f78..cf66d624 100644
--- a/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/Startup.cs
+++ b/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/Startup.cs
@@ -19,7 +19,7 @@ public class Startup {
Environment.SetDevelopment();
} )
.AsBuild()
- .AddSerilog( t => t.AddExceptionless() )
+ .AddExceptionless()
.AddUtil();
}
diff --git a/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/appsettings.json b/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/appsettings.json
index 6cf94af6..7a753ca9 100644
--- a/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/appsettings.json
+++ b/test/Util.Logging.Serilog.Exceptionless.Tests.Integration/appsettings.json
@@ -6,8 +6,8 @@
}
},
"Exceptionless": {
- "ApiKey": "0ntTeU4QFBKCm1FIM9sjr4NKaXkXTEBeRKch5tL9",
- "ServerUrl": "http://127.0.0.1:8095",
+ "ApiKey": "8JtknZBV1NRC7bdsv6SF5cbBFrMZipWMkARZxkxo",
+ "ServerUrl": "http://localhost:5480",
"QueueMaxAttempts": 1
}
}
\ No newline at end of file
diff --git a/test/Util.TestShare/Models/Product.cs b/test/Util.TestShare/Models/Product.cs
index 9dad7af5..25571f67 100644
--- a/test/Util.TestShare/Models/Product.cs
+++ b/test/Util.TestShare/Models/Product.cs
@@ -192,4 +192,11 @@ public class Product : AggregateRoot, IDelete, ITenant, IAudited, IExtr
public void TestDomainEvent2() {
AddDomainEvent( new TestEvent3( Id, "a" ) );
}
+
+ ///
+ /// 获取扩展属性Json
+ ///
+ public string GetExtraPropertiesJson() {
+ return Util.Helpers.Json.ToJson( ExtraProperties );
+ }
}
\ No newline at end of file