mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-28 19:18:08 +08:00
修改Exceptionless 日志配置方法为 AddExceptionless
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using Util.Aop;
|
||||
using Util.Domain;
|
||||
using Util.Validation;
|
||||
using Util.Domain;
|
||||
|
||||
namespace Util.Data.Stores;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using Util.Data.Dapper.TypeHandlers;
|
||||
using Util.Infrastructure;
|
||||
|
||||
namespace Util.Data.Dapper.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Oracle Dapper服务注册器
|
||||
/// </summary>
|
||||
public class OracleDapperServiceRegistrar : IServiceRegistrar {
|
||||
/// <summary>
|
||||
/// 获取服务名
|
||||
/// </summary>
|
||||
public static string ServiceName => "Util.Data.Dapper.Infrastructure.OracleDapperServiceRegistrar";
|
||||
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public int OrderId => 812;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enabled => ServiceRegistrarConfig.IsEnabled( ServiceName );
|
||||
|
||||
/// <summary>
|
||||
/// 注册服务
|
||||
/// </summary>
|
||||
/// <param name="serviceContext">服务上下文</param>
|
||||
public Action Register( ServiceContext serviceContext ) {
|
||||
SqlMapper.RemoveTypeMap( typeof( Guid ) );
|
||||
SqlMapper.RemoveTypeMap( typeof( Guid? ) );
|
||||
SqlMapper.AddTypeHandler( typeof( Guid ), new GuidTypeHandler() );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Util.Infrastructure;
|
||||
|
||||
namespace Util.Data.Dapper.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Oracle Dapper服务注册器配置扩展
|
||||
/// </summary>
|
||||
public static class ServiceRegistrarConfigExtensions {
|
||||
/// <summary>
|
||||
/// 启用Oracle Dapper服务注册器
|
||||
/// </summary>
|
||||
/// <param name="config">服务注册器配置</param>
|
||||
public static ServiceRegistrarConfig EnableOracleDapperServiceRegistrar( this ServiceRegistrarConfig config ) {
|
||||
ServiceRegistrarConfig.Enable( OracleDapperServiceRegistrar.ServiceName );
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///禁用Oracle Dapper服务注册器
|
||||
/// </summary>
|
||||
/// <param name="config">服务注册器配置</param>
|
||||
public static ServiceRegistrarConfig DisableOracleDapperServiceRegistrar( this ServiceRegistrarConfig config ) {
|
||||
ServiceRegistrarConfig.Disable( OracleDapperServiceRegistrar.ServiceName );
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -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<TImplementation> ), ( sp ) => options );
|
||||
RegisterGuidTypeHandler();
|
||||
} );
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册Guid类型处理器
|
||||
/// </summary>
|
||||
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<TImplementation> ), ( sp ) => options );
|
||||
RegisterGuidTypeHandler();
|
||||
} );
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -8,25 +8,64 @@ namespace Util.Logging.Serilog;
|
||||
/// </summary>
|
||||
public static class AppBuilderExtensions {
|
||||
/// <summary>
|
||||
/// 配置Serilog日志操作
|
||||
/// 配置Exceptionless日志操作
|
||||
/// </summary>
|
||||
/// <param name="builder">应用生成器</param>
|
||||
/// <param name="isClearProviders">是否清除默认设置的日志提供程序</param>
|
||||
public static IAppBuilder AddExceptionless( this IAppBuilder builder, bool isClearProviders = false ) {
|
||||
return builder.AddExceptionless( null, isClearProviders );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Exceptionless日志操作
|
||||
/// </summary>
|
||||
/// <param name="builder">应用生成器</param>
|
||||
/// <param name="appName">应用程序名称</param>
|
||||
public static IAppBuilder AddExceptionless( this IAppBuilder builder, string appName ) {
|
||||
return builder.AddExceptionless( null, appName );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Exceptionless日志操作
|
||||
/// </summary>
|
||||
/// <param name="builder">应用生成器</param>
|
||||
/// <param name="configAction">Exceptionless日志配置操作</param>
|
||||
/// <param name="isClearProviders">是否清除默认设置的日志提供程序</param>
|
||||
public static IAppBuilder AddSerilog( this IAppBuilder builder, Action<SerilogExceptionlessConfiguration> configAction, bool isClearProviders = false ) {
|
||||
public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action<ExceptionlessConfiguration> configAction, bool isClearProviders = false ) {
|
||||
return builder.AddExceptionless( configAction, t => t.IsClearProviders = isClearProviders );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Exceptionless日志操作
|
||||
/// </summary>
|
||||
/// <param name="builder">应用生成器</param>
|
||||
/// <param name="configAction">Exceptionless日志配置操作</param>
|
||||
/// <param name="appName">应用程序名称</param>
|
||||
public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action<ExceptionlessConfiguration> configAction, string appName ) {
|
||||
return builder.AddExceptionless( configAction, t => t.Application = appName );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置Exceptionless日志操作
|
||||
/// </summary>
|
||||
/// <param name="builder">应用生成器</param>
|
||||
/// <param name="configAction">Exceptionless日志配置操作</param>
|
||||
/// <param name="setupAction">日志配置</param>
|
||||
public static IAppBuilder AddExceptionless( this IAppBuilder builder, Action<ExceptionlessConfiguration> configAction, Action<LogOptions> 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<ILogFactory, LogFactory>();
|
||||
services.AddTransient( typeof( ILog<> ), typeof( Log<> ) );
|
||||
services.AddTransient( typeof( ILog ), t => t.GetService<ILogFactory>()?.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()
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
namespace Util.Logging.Serilog;
|
||||
|
||||
/// <summary>
|
||||
/// Serilog Exceptionless日志配置
|
||||
/// </summary>
|
||||
public class SerilogExceptionlessConfiguration {
|
||||
/// <summary>
|
||||
/// 添加Exceptionless日志组件
|
||||
/// </summary>
|
||||
public void AddExceptionless() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加Exceptionless日志组件
|
||||
/// </summary>
|
||||
/// <param name="configAction">Exceptionless日志配置操作</param>
|
||||
public void AddExceptionless( Action<ExceptionlessConfiguration> configAction ) {
|
||||
ConfigAction = configAction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exceptionless日志配置操作
|
||||
/// </summary>
|
||||
internal Action<ExceptionlessConfiguration> ConfigAction { get; private set; }
|
||||
}
|
||||
Reference in New Issue
Block a user