feat: 重构扩展类命名空间
This commit is contained in:
parent
19a2123cee
commit
614d3d6b43
|
@ -19,7 +19,7 @@ namespace Microsoft.Extensions.DependencyInjection;
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ServicesExtensions
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
|
@ -1,6 +1,6 @@
|
|||
using Bootstrap.Security.Blazor;
|
||||
|
||||
namespace BootstrapAdmin.Web.Core;
|
||||
namespace BootstrapAdmin.Web.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
///
|
|
@ -1,24 +1,23 @@
|
|||
namespace BootstrapAdmin.Web.Extensions
|
||||
namespace Microsoft.AspNetCore.Builder;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ApplicationBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ApplicationBuilderExtensions
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static WebApplication UseBootstrapBlazorAdmin(this WebApplication builder)
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static WebApplication UseBootstrapBlazorAdmin(this WebApplication builder)
|
||||
{
|
||||
// 开启健康检查
|
||||
builder.MapBootstrapHealthChecks();
|
||||
// 开启健康检查
|
||||
builder.MapBootstrapHealthChecks();
|
||||
|
||||
builder.UseAuthentication();
|
||||
builder.UseAuthorization();
|
||||
builder.UseAuthentication();
|
||||
builder.UseAuthorization();
|
||||
|
||||
return builder;
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,84 +2,83 @@
|
|||
using Microsoft.Extensions.Logging.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace BootstrapAdmin.Web.Extensions
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 邮件日志扩展方法
|
||||
/// </summary>
|
||||
static class CloudLoggerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件日志扩展方法
|
||||
/// 注册邮件日志方法
|
||||
/// </summary>
|
||||
public static class CloudLoggerExtensions
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static ILoggingBuilder AddCloudLogger(this ILoggingBuilder builder)
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册邮件日志方法
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static ILoggingBuilder AddCloudLogger(this ILoggingBuilder builder)
|
||||
{
|
||||
builder.Services.AddSingleton<IConfigureOptions<CloudLoggerOption>, LoggerProviderConfigureOptions<CloudLoggerOption, CloudLoggerProvider>>();
|
||||
builder.Services.AddSingleton<IOptionsChangeTokenSource<CloudLoggerOption>, LoggerProviderOptionsChangeTokenSource<CloudLoggerOption, CloudLoggerProvider>>();
|
||||
builder.Services.AddSingleton<ILoggerProvider, CloudLoggerProvider>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 云日志提供类
|
||||
/// </summary>
|
||||
[ProviderAlias("Cloud")]
|
||||
public class CloudLoggerProvider : LoggerProvider
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
private readonly IDisposable optionsReloadToken;
|
||||
private CloudLoggerOption option;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CloudLoggerProvider(IOptionsMonitor<CloudLoggerOption> options) : base(null, new Func<string, LogLevel, bool>((name, logLevel) => logLevel >= LogLevel.Error))
|
||||
{
|
||||
optionsReloadToken = options.OnChange(op => option = op);
|
||||
option = options.CurrentValue;
|
||||
|
||||
httpClient = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
httpClient.DefaultRequestHeaders.Connection.Add("keep-alive");
|
||||
|
||||
LogCallback = new Action<string>(async message =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(option.Url))
|
||||
{
|
||||
try { await httpClient.PostAsJsonAsync(option.Url, message); }
|
||||
catch { }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
{
|
||||
httpClient.Dispose();
|
||||
optionsReloadToken.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 云日志配置类
|
||||
/// </summary>
|
||||
public class CloudLoggerOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 云日志地址
|
||||
/// </summary>
|
||||
public string Url { get; set; } = "";
|
||||
builder.Services.AddSingleton<IConfigureOptions<CloudLoggerOption>, LoggerProviderConfigureOptions<CloudLoggerOption, CloudLoggerProvider>>();
|
||||
builder.Services.AddSingleton<IOptionsChangeTokenSource<CloudLoggerOption>, LoggerProviderOptionsChangeTokenSource<CloudLoggerOption, CloudLoggerProvider>>();
|
||||
builder.Services.AddSingleton<ILoggerProvider, CloudLoggerProvider>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 云日志提供类
|
||||
/// </summary>
|
||||
[ProviderAlias("Cloud")]
|
||||
class CloudLoggerProvider : LoggerProvider
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
private readonly IDisposable optionsReloadToken;
|
||||
private CloudLoggerOption option;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CloudLoggerProvider(IOptionsMonitor<CloudLoggerOption> options) : base(null, new Func<string, LogLevel, bool>((name, logLevel) => logLevel >= LogLevel.Error))
|
||||
{
|
||||
optionsReloadToken = options.OnChange(op => option = op);
|
||||
option = options.CurrentValue;
|
||||
|
||||
httpClient = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
httpClient.DefaultRequestHeaders.Connection.Add("keep-alive");
|
||||
|
||||
LogCallback = new Action<string>(async message =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(option.Url))
|
||||
{
|
||||
try { await httpClient.PostAsJsonAsync(option.Url, message); }
|
||||
catch { }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
{
|
||||
httpClient.Dispose();
|
||||
optionsReloadToken.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 云日志配置类
|
||||
/// </summary>
|
||||
class CloudLoggerOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 云日志地址
|
||||
/// </summary>
|
||||
public string Url { get; set; } = "";
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Core.Services;
|
||||
using BootstrapAdmin.Web.HealthChecks;
|
||||
using BootstrapAdmin.Web.Services;
|
||||
using BootstrapAdmin.Web.Services.SMS;
|
||||
using BootstrapAdmin.Web.Services.SMS.Tencent;
|
||||
using BootstrapAdmin.Web.Utils;
|
||||
|
||||
namespace BootstrapAdmin.Web.Extensions
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ServicesExtensions
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加示例后台任务
|
Loading…
Reference in New Issue