diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index be65d756e..bc28da9f3 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -363,6 +363,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.DataProtection" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.DataProtection.EntityFrameworkCore", "modules\data-protection\LINGYUN.Abp.DataProtection.EntityFrameworkCore\LINGYUN.Abp.DataProtection.EntityFrameworkCore.csproj", "{19B860CA-2E1E-45CC-A5E2-ED3F2BCEAB5D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.IdGenerator", "modules\common\LINGYUN.Abp.IdGenerator\LINGYUN.Abp.IdGenerator.csproj", "{440C9BD9-85EA-4473-AB1C-7C3562DF4915}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Serilog.Enrichers.UniqueId", "modules\logging\LINGYUN.Abp.Serilog.Enrichers.UniqueId\LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj", "{23C3B247-523A-4FBF-B785-2F035E0089BD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -941,6 +945,14 @@ Global {19B860CA-2E1E-45CC-A5E2-ED3F2BCEAB5D}.Debug|Any CPU.Build.0 = Debug|Any CPU {19B860CA-2E1E-45CC-A5E2-ED3F2BCEAB5D}.Release|Any CPU.ActiveCfg = Release|Any CPU {19B860CA-2E1E-45CC-A5E2-ED3F2BCEAB5D}.Release|Any CPU.Build.0 = Release|Any CPU + {440C9BD9-85EA-4473-AB1C-7C3562DF4915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {440C9BD9-85EA-4473-AB1C-7C3562DF4915}.Debug|Any CPU.Build.0 = Debug|Any CPU + {440C9BD9-85EA-4473-AB1C-7C3562DF4915}.Release|Any CPU.ActiveCfg = Release|Any CPU + {440C9BD9-85EA-4473-AB1C-7C3562DF4915}.Release|Any CPU.Build.0 = Release|Any CPU + {23C3B247-523A-4FBF-B785-2F035E0089BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23C3B247-523A-4FBF-B785-2F035E0089BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23C3B247-523A-4FBF-B785-2F035E0089BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23C3B247-523A-4FBF-B785-2F035E0089BD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1120,6 +1132,8 @@ Global {529DF802-97C4-4BF2-BE7C-39663B3D9EA3} = {C5CAD011-DF84-4914-939C-0C029DCEF26F} {BB840DEE-1F5F-45AA-A82F-4E7B7DC4F156} = {529DF802-97C4-4BF2-BE7C-39663B3D9EA3} {19B860CA-2E1E-45CC-A5E2-ED3F2BCEAB5D} = {529DF802-97C4-4BF2-BE7C-39663B3D9EA3} + {440C9BD9-85EA-4473-AB1C-7C3562DF4915} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} + {23C3B247-523A-4FBF-B785-2F035E0089BD} = {6FC0578B-CDF1-43AD-9F7E-4AA7E4720A02} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs index f8ae32e81..89e163a61 100644 --- a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs @@ -242,51 +242,51 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch if (startTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.ExecutionTime).GreaterThanOrEquals(startTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(AuditLog.ExecutionTime))).GreaterThanOrEquals(startTime))); } if (endTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.ExecutionTime).LessThanOrEquals(endTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(AuditLog.ExecutionTime))).LessThanOrEquals(endTime))); } if (!httpMethod.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.HttpMethod.Suffix("keyword")).Value(httpMethod))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.HttpMethod))).Value(httpMethod))); } if (!url.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Match((q) => q.Field(f => f.Url.Suffix("keyword")).Query(url))); + querys.Add((log) => log.Match((q) => q.Field(GetField(nameof(AuditLog.Url))).Query(url))); } if (userId.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.UserId.Suffix("keyword")).Value(userId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.UserId))).Value(userId))); } if (!userName.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.UserName.Suffix("keyword")).Value(userName))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.UserName))).Value(userName))); } if (!applicationName.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ApplicationName.Suffix("keyword")).Value(applicationName))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.ApplicationName))).Value(applicationName))); } if (!correlationId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.CorrelationId.Suffix("keyword")).Value(correlationId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.CorrelationId))).Value(correlationId))); } if (!clientId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ClientId.Suffix("keyword")).Value(clientId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.ClientId))).Value(clientId))); } if (!clientIpAddress.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ClientIpAddress.Suffix("keyword")).Value(clientIpAddress))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.ClientIpAddress))).Value(clientIpAddress))); } if (maxExecutionDuration.HasValue) { - querys.Add((log) => log.Range((q) => q.Field(f => f.ExecutionDuration).LessThanOrEquals(maxExecutionDuration))); + querys.Add((log) => log.Range((q) => q.Field(GetField(nameof(AuditLog.ExecutionDuration))).LessThanOrEquals(maxExecutionDuration))); } if (minExecutionDuration.HasValue) { - querys.Add((log) => log.Range((q) => q.Field(f => f.ExecutionDuration).GreaterThanOrEquals(minExecutionDuration))); + querys.Add((log) => log.Range((q) => q.Field(GetField(nameof(AuditLog.ExecutionDuration))).GreaterThanOrEquals(minExecutionDuration))); } @@ -317,7 +317,7 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch if (httpStatusCode.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.HttpStatusCode).Value(httpStatusCode))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(AuditLog.HttpStatusCode))).Value(httpStatusCode))); } return querys; @@ -344,7 +344,10 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch { "CorrelationId", "CorrelationId.keyword" }, { "BrowserInfo", "BrowserInfo.keyword" }, { "HttpMethod", "HttpMethod.keyword" }, - { "Url", "Url.keyword" } + { "Url", "Url.keyword" }, + { "ExecutionDuration", "ExecutionDuration" }, + { "ExecutionTime", "ExecutionTime" }, + { "HttpStatusCode", "HttpStatusCode" }, }; protected virtual string GetField(string field) { diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchSecurityLogManager.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchSecurityLogManager.cs index 3905014ec..e8d00bb36 100644 --- a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchSecurityLogManager.cs +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchSecurityLogManager.cs @@ -192,43 +192,43 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch if (startTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.CreationTime).GreaterThanOrEquals(startTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(SecurityLog.CreationTime))).GreaterThanOrEquals(startTime))); } if (endTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.CreationTime).LessThanOrEquals(endTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(SecurityLog.CreationTime))).LessThanOrEquals(endTime))); } if (!applicationName.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ApplicationName.Suffix("keyword")).Value(applicationName))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.ApplicationName))).Value(applicationName))); } if (!identity.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Identity.Suffix("keyword")).Value(identity))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.Identity))).Value(identity))); } if (!action.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Action.Suffix("keyword")).Value(action))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.Action))).Value(action))); } if (userId.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.UserId.Suffix("keyword")).Value(userId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.UserId))).Value(userId))); } if (!userName.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.UserName.Suffix("keyword")).Value(userName))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.UserName))).Value(userName))); } if (!clientId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ClientId.Suffix("keyword")).Value(clientId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.ClientId))).Value(clientId))); } if (!clientIpAddress.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.ClientIpAddress.Suffix("keyword")).Value(clientIpAddress))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.ClientIpAddress))).Value(clientIpAddress))); } if (!correlationId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.CorrelationId.Suffix("keyword")).Value(correlationId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SecurityLog.CorrelationId))).Value(correlationId))); } return querys; @@ -253,6 +253,7 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch { "ClientIpAddress", "ClientIpAddress.keyword" }, { "ClientId", "ClientId.keyword" }, { "CorrelationId", "CorrelationId.keyword" }, + { "CreationTime", "CreationTime" }, }; protected virtual string GetField(string field) { diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/Logging/Dto/LogFieldDto.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/Logging/Dto/LogFieldDto.cs index 24529f75a..b18b30d9f 100644 --- a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/Logging/Dto/LogFieldDto.cs +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/Logging/Dto/LogFieldDto.cs @@ -2,6 +2,7 @@ { public class LogFieldDto { + public string Id { get; set; } public string MachineName { get; set; } public string Environment { get; set; } public string Application { get; set; } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs index ac9e07167..8a574e615 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.IM.Contract; +using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.IM.Contract; using LINGYUN.Abp.IM.Groups; using LINGYUN.Abp.IM.Localization; using LINGYUN.Abp.IM.Messages; @@ -28,7 +29,7 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs protected IUserOnlineChanger OnlineChanger => LazyServiceProvider.LazyGetService(); - protected ISnowflakeIdrGenerator SnowflakeIdrGenerator => LazyServiceProvider.LazyGetRequiredService(); + protected IDistributedIdGenerator DistributedIdGenerator => LazyServiceProvider.LazyGetRequiredService(); protected IExceptionToErrorInfoConverter ErrorInfoConverter => LazyServiceProvider.LazyGetRequiredService(); @@ -147,7 +148,7 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs try { chatMessage.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); - chatMessage.MessageId = SnowflakeIdrGenerator.Create().ToString(); + chatMessage.MessageId = DistributedIdGenerator.Create().ToString(); await MessageStore.StoreMessageAsync(chatMessage); if (!chatMessage.GroupId.IsNullOrWhiteSpace()) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj index 271ccdc54..a65058fd2 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj @@ -1,4 +1,4 @@ - + @@ -22,6 +22,7 @@ + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/AbpIMModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/AbpIMModule.cs index e36420f02..c97cd5dd6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/AbpIMModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/AbpIMModule.cs @@ -1,5 +1,6 @@ using LINGYUN.Abp.IM.Localization; using LINGYUN.Abp.RealTime; +using LINGYUN.Abp.IdGenerator; using Volo.Abp.EventBus; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -10,7 +11,8 @@ namespace LINGYUN.Abp.IM [DependsOn( typeof(AbpEventBusModule), typeof(AbpRealTimeModule), - typeof(AbpLocalizationModule))] + typeof(AbpLocalizationModule), + typeof(AbpIdGeneratorModule))] public class AbpIMModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs index cfc0c1e23..9a941ace6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.RealTime; +using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.RealTime; using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -9,19 +10,19 @@ namespace LINGYUN.Abp.IM.Messages public class MessageSender : IMessageSender, ITransientDependency { protected IDistributedEventBus EventBus { get; } - protected ISnowflakeIdrGenerator SnowflakeIdrGenerator { get; } + protected IDistributedIdGenerator DistributedIdGenerator { get; } public MessageSender( IDistributedEventBus eventBus, - ISnowflakeIdrGenerator snowflakeIdrGenerator) + IDistributedIdGenerator distributedIdGenerator) { EventBus = eventBus; - SnowflakeIdrGenerator = snowflakeIdrGenerator; + DistributedIdGenerator = distributedIdGenerator; } public virtual async Task SendMessageAsync(ChatMessage chatMessage) { chatMessage.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); - chatMessage.MessageId = SnowflakeIdrGenerator.Create().ToString(); + chatMessage.MessageId = DistributedIdGenerator.Create().ToString(); // 如果先存储的话,就紧耦合消息处理模块了 // await Store.StoreMessageAsync(chatMessage); var eto = new RealTimeEto(chatMessage); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xml b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xsd b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xsd new file mode 100644 index 000000000..11da52550 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN.Abp.IdGenerator.csproj b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN.Abp.IdGenerator.csproj new file mode 100644 index 000000000..a96345896 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN.Abp.IdGenerator.csproj @@ -0,0 +1,15 @@ + + + + + + + netstandard2.0 + + + + + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/AbpIdGeneratorModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/AbpIdGeneratorModule.cs new file mode 100644 index 000000000..f1cb7e872 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/AbpIdGeneratorModule.cs @@ -0,0 +1,17 @@ +using LINGYUN.Abp.IdGenerator.Snowflake; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.IdGenerator; + +public class AbpIdGeneratorModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var snowflakeIdOptions = new SnowflakeIdOptions(); + context.Services.ExecutePreConfiguredActions(snowflakeIdOptions); + + context.Services.TryAddSingleton(SnowflakeIdGenerator.Create(snowflakeIdOptions)); + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/IDistributedIdGenerator.cs b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/IDistributedIdGenerator.cs new file mode 100644 index 000000000..8329de385 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/IDistributedIdGenerator.cs @@ -0,0 +1,6 @@ +namespace LINGYUN.Abp.IdGenerator; + +public interface IDistributedIdGenerator +{ + long Create(); +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdGenerator.cs similarity index 61% rename from aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs rename to aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdGenerator.cs index 2f9eaab9f..22f4f9f7b 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdGenerator.cs @@ -1,13 +1,11 @@ -using Microsoft.Extensions.Options; -using System; +using System; using Volo.Abp; -using Volo.Abp.DependencyInjection; -namespace LINGYUN.Abp.RealTime +namespace LINGYUN.Abp.IdGenerator.Snowflake { // reference: https://github.com/dotnetcore/CAP // reference: https://blog.csdn.net/lq18050010830/article/details/89845790 - public class SnowflakeIdrGenerator : ISnowflakeIdrGenerator, ISingletonDependency + public class SnowflakeIdGenerator : IDistributedIdGenerator { public const long Twepoch = 1288834974657L; @@ -22,48 +20,48 @@ namespace LINGYUN.Abp.RealTime protected int TimestampLeftShift { get; } protected long SequenceMask { get; } - protected SnowflakeIdOptions Options { get; } - - public SnowflakeIdrGenerator(IOptions options) + private SnowflakeIdGenerator(SnowflakeIdOptions options) { - Options = options.Value; - - WorkerIdShift = Options.SequenceBits; - DatacenterIdShift = Options.SequenceBits + Options.WorkerIdBits; - TimestampLeftShift = Options.SequenceBits + Options.WorkerIdBits + Options.DatacenterIdBits; - SequenceMask = -1L ^ (-1L << Options.SequenceBits); + WorkerIdShift = options.SequenceBits; + DatacenterIdShift = options.SequenceBits + options.WorkerIdBits; + TimestampLeftShift = options.SequenceBits + options.WorkerIdBits + options.DatacenterIdBits; + SequenceMask = -1L ^ (-1L << options.SequenceBits); } - internal void Initialize(long sequence = 0L) + public static SnowflakeIdGenerator Create(SnowflakeIdOptions options) { - Sequence = sequence; - MaxWorkerId = -1L ^ (-1L << Options.WorkerIdBits); - MaxDatacenterId = -1L ^ (-1L << Options.DatacenterIdBits); + var idGenerator = new SnowflakeIdGenerator(options) + { + Sequence = options.Sequence, + MaxWorkerId = -1L ^ (-1L << options.WorkerIdBits), + MaxDatacenterId = -1L ^ (-1L << options.DatacenterIdBits) + }; if (!int.TryParse(Environment.GetEnvironmentVariable("WORKERID", EnvironmentVariableTarget.Machine), out var workerId)) { - workerId = RandomHelper.GetRandom((int)MaxWorkerId); + workerId = RandomHelper.GetRandom((int)idGenerator.MaxWorkerId); } if (!int.TryParse(Environment.GetEnvironmentVariable("DATACENTERID", EnvironmentVariableTarget.Machine), out var datacenterId)) { - datacenterId = RandomHelper.GetRandom((int)MaxDatacenterId); + datacenterId = RandomHelper.GetRandom((int)idGenerator.MaxDatacenterId); } - if (workerId > MaxWorkerId || workerId < 0) - throw new ArgumentException($"worker Id can't be greater than {MaxWorkerId} or less than 0"); + if (workerId > idGenerator.MaxWorkerId || workerId < 0) + throw new ArgumentException($"worker Id can't be greater than {idGenerator.MaxWorkerId} or less than 0"); - if (datacenterId > MaxDatacenterId || datacenterId < 0) - throw new ArgumentException($"datacenter Id can't be greater than {MaxDatacenterId} or less than 0"); + if (datacenterId > idGenerator.MaxDatacenterId || datacenterId < 0) + throw new ArgumentException($"datacenter Id can't be greater than {idGenerator.MaxDatacenterId} or less than 0"); + + idGenerator.WorkerId = workerId; + idGenerator.DatacenterId = datacenterId; - WorkerId = workerId; - DatacenterId = datacenterId; - + return idGenerator; } - public long WorkerId { get; protected set; } - public long DatacenterId { get; protected set; } - public long Sequence { get; protected set; } + public long WorkerId { get; internal set; } + public long DatacenterId { get; internal set; } + public long Sequence { get; internal set; } public virtual long Create() { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdOptions.cs new file mode 100644 index 000000000..06b884c97 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdOptions.cs @@ -0,0 +1,29 @@ +namespace LINGYUN.Abp.IdGenerator.Snowflake; + +public class SnowflakeIdOptions +{ + /// + /// 机器Id长度 + /// + public int WorkerIdBits { get; set; } + /// + /// 机房Id长度 + /// + public int DatacenterIdBits { get; set; } + /// + /// 12bit 的序号 + /// + public long Sequence { get; set; } + /// + /// 每秒生成Id的数量 + /// + public int SequenceBits { get; set; } + + public SnowflakeIdOptions() + { + WorkerIdBits = 5; + DatacenterIdBits = 5; + Sequence = 0L; + SequenceBits = 12; + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj index 01eea5617..063bb437d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj @@ -1,4 +1,4 @@ - + @@ -16,6 +16,7 @@ + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs index 2b210fe05..e5c92e07c 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.Notifications.Internal; +using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.Notifications.Internal; using LINGYUN.Abp.RealTime; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -16,6 +17,7 @@ namespace LINGYUN.Abp.Notifications [DependsOn( typeof(AbpBackgroundWorkersModule), typeof(AbpBackgroundJobsAbstractionsModule), + typeof(AbpIdGeneratorModule), typeof(AbpJsonModule), typeof(AbpRealTimeModule))] public class AbpNotificationModule : AbpModule diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs index cc5e55902..365b018e4 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.RealTime; +using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.RealTime; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -26,19 +27,19 @@ namespace LINGYUN.Abp.Notifications /// public IDistributedEventBus DistributedEventBus { get; } /// - /// Reference to . + /// Reference to . /// - protected ISnowflakeIdrGenerator SnowflakeIdGenerator { get; } + protected IDistributedIdGenerator DistributedIdGenerator { get; } protected AbpNotificationOptions Options { get; } public NotificationSender( IDistributedEventBus distributedEventBus, - ISnowflakeIdrGenerator snowflakeIdrGenerator, + IDistributedIdGenerator distributedIdGenerator, IOptions options) { Options = options.Value; DistributedEventBus = distributedEventBus; - SnowflakeIdGenerator = snowflakeIdrGenerator; + DistributedIdGenerator = distributedIdGenerator; Logger = NullLogger.Instance; } @@ -79,7 +80,7 @@ namespace LINGYUN.Abp.Notifications { var eto = new NotificationEto(data) { - Id = SnowflakeIdGenerator.Create(), + Id = DistributedIdGenerator.Create(), TenantId = tenantId, Users = users?.ToList(), Name = name, diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs index 4eb61246e..7407dc6a3 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.EventBus.Abstractions; +using Volo.Abp.EventBus.Abstractions; using Volo.Abp.Modularity; namespace LINGYUN.Abp.RealTime @@ -8,12 +6,5 @@ namespace LINGYUN.Abp.RealTime [DependsOn(typeof(AbpEventBusAbstractionsModule))] public class AbpRealTimeModule : AbpModule { - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - context - .ServiceProvider - .GetRequiredService() - .Initialize(); - } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs deleted file mode 100644 index bc982928c..000000000 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LINGYUN.Abp.RealTime -{ - public interface ISnowflakeIdrGenerator - { - long Create(); - } -} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs deleted file mode 100644 index 62a63c53d..000000000 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace LINGYUN.Abp.RealTime -{ - public class SnowflakeIdOptions - { - /// - /// 机器Id长度 - /// - public int WorkerIdBits { get; set; } - /// - /// 机房Id长度 - /// - public int DatacenterIdBits { get; set; } - /// - /// 每秒生成Id的数量 - /// - public int SequenceBits { get; set; } - public SnowflakeIdOptions() - { - WorkerIdBits = 5; - DatacenterIdBits = 5; - SequenceBits = 12; - } - } -} diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj index 52b55c9cd..a83999859 100644 --- a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj @@ -18,6 +18,7 @@ + diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs index 73aa97176..8d1560626 100644 --- a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs @@ -7,7 +7,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch public AbpLoggingSerilogElasticsearchMapperProfile() { CreateMap(); - CreateMap(); + CreateMap() + .ForMember(log => log.Id, map => map.MapFrom(slog => slog.UniqueId.ToString())); CreateMap(); } } diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs index 56a16eaa6..44fad6311 100644 --- a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs @@ -1,5 +1,6 @@ using LINGYUN.Abp.Elasticsearch; using LINGYUN.Abp.Serilog.Enrichers.Application; +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -71,8 +72,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch }, { "term": { - "@timestamp": { - "value": "2021-10-31T09:53:12.3406273+08:00" + "fields.UniqueId": { + "value": "1474021081433481216" } } } @@ -87,9 +88,9 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch (q) => q.Bool( (b) => b.Must( (s) => s.Term( - (t) => t.Field("@timestamp").Value(id)), + (t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id)), (s) => s.Term( - (t) => t.Field(f => f.Fields.TenantId.Suffix("keyword")).Value(_currentTenant.GetId()))))), + (t) => t.Field(GetField(nameof(SerilogInfo.Fields.TenantId))).Value(_currentTenant.GetId()))))), cancellationToken); } else @@ -100,8 +101,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch "must": [ { "term": { - "@timestamp": { - "value": "2021-10-31T09:53:12.3406273+08:00" + "fields.UniqueId": { + "value": "1474021081433481216" } } } @@ -116,7 +117,7 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch (q) => q.Bool( (b) => b.Must( (s) => s.Term( - (t) => t.Field("@timestamp").Value(id))))), + (t) => t.Field(GetField(nameof(SerilogInfo.Fields.UniqueId))).Value(id))))), cancellationToken); } @@ -210,7 +211,9 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch var sortOrder = !sorting.IsNullOrWhiteSpace() && sorting.EndsWith("asc", StringComparison.InvariantCultureIgnoreCase) ? SortOrder.Ascending : SortOrder.Descending; - sorting = sorting ?? "timestamp"; + sorting = !sorting.IsNullOrWhiteSpace() + ? sorting.Split()[0] + : nameof(SerilogInfo.TimeStamp); var querys = BuildQueryDescriptor( startTime, @@ -241,7 +244,9 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch var response = await client.SearchAsync((dsl) => dsl.Index(CreateIndex()) - .Query(log => log.Bool(b => b.Must(querys.ToArray()))) + .Query(log => + log.Bool(b => + b.Must(querys.ToArray()))) .Source(SourceFilter) .Sort(log => log.Field(GetField(sorting), sortOrder)) .From(skipCount) @@ -270,55 +275,56 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch if (_currentTenant.IsAvailable) { - querys.Add((log) => log.Term((q) => q.Field((f) => f.Fields.TenantId.Suffix("keyword")).Value(_currentTenant.GetId()))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.TenantId))).Value(_currentTenant.GetId()))); } if (startTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.TimeStamp).GreaterThanOrEquals(startTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(SerilogInfo.TimeStamp))).GreaterThanOrEquals(startTime))); } if (endTime.HasValue) { - querys.Add((log) => log.DateRange((q) => q.Field(f => f.TimeStamp).LessThanOrEquals(endTime))); + querys.Add((log) => log.DateRange((q) => q.Field(GetField(nameof(SerilogInfo.TimeStamp))).LessThanOrEquals(endTime))); } if (level.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Level.Suffix("keyword")).Value(level.ToString()))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Level))).Value(level.ToString()))); } if (!machineName.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field((f) => f.Fields.MachineName.Suffix("keyword")).Value(machineName))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.MachineName))).Value(machineName))); } if (!environment.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field((f) => f.Fields.Environment.Suffix("keyword")).Value(environment))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.Environment))).Value(environment))); } if (!application.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field((f) => f.Fields.Application.Suffix("keyword")).Value(application))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.Application))).Value(application))); } if (!context.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field((f) => f.Fields.Context.Suffix("keyword")).Value(context))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.Context))).Value(context))); } if (!requestId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Match((q) => q.Field(f => f.Fields.RequestId.Suffix("keyword")).Query(requestId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.RequestId))).Value(requestId))); } if (!requestPath.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Fields.RequestPath.Suffix("keyword")).Value(requestPath))); + // 模糊匹配 + querys.Add((log) => log.MatchPhrasePrefix((q) => q.Field(f => f.Fields.RequestPath).Query(requestPath))); } if (!correlationId.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Fields.CorrelationId.Suffix("keyword")).Value(correlationId))); + querys.Add((log) => log.MatchPhrase((q) => q.Field(GetField(nameof(SerilogInfo.Fields.CorrelationId))).Query(correlationId))); } if (processId.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Fields.ProcessId).Value(processId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.ProcessId))).Value(processId))); } if (threadId.HasValue) { - querys.Add((log) => log.Term((q) => q.Field(f => f.Fields.ThreadId).Value(threadId))); + querys.Add((log) => log.Term((q) => q.Field(GetField(nameof(SerilogInfo.Fields.ThreadId))).Value(threadId))); } if (hasException.HasValue) @@ -386,6 +392,8 @@ namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch { "userid", "fields.UserId.keyword" }, { "processid", "fields.ProcessId" }, { "threadid", "fields.ThreadId" }, + { "id", $"fields.{AbpSerilogUniqueIdConsts.UniqueIdPropertyName}" }, + { "uniqueid", $"fields.{AbpSerilogUniqueIdConsts.UniqueIdPropertyName}" }, }; protected virtual string GetField(string field) { diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogField.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogField.cs index 7409aab49..0ef275557 100644 --- a/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogField.cs +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogField.cs @@ -1,10 +1,14 @@ using LINGYUN.Abp.Serilog.Enrichers.Application; +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; using System; namespace LINGYUN.Abp.Logging.Serilog.Elasticsearch { public class SerilogField { + [Nest.PropertyName(AbpSerilogUniqueIdConsts.UniqueIdPropertyName)] + public long UniqueId { get; set; } + [Nest.PropertyName(AbpLoggingEnricherPropertyNames.MachineName)] public string MachineName { get; set; } diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Logging/LINGYUN/Abp/AuditLogging/LogField.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Logging/LINGYUN/Abp/AuditLogging/LogField.cs index a91996afb..11c296850 100644 --- a/aspnet-core/modules/logging/LINGYUN.Abp.Logging/LINGYUN/Abp/AuditLogging/LogField.cs +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Logging/LINGYUN/Abp/AuditLogging/LogField.cs @@ -2,6 +2,7 @@ { public class LogField { + public string Id { get; set; } public string MachineName { get; set; } public string Environment { get; set; } public string Application { get; set; } diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xml b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xml new file mode 100644 index 000000000..ac6b5b292 --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xsd b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xsd new file mode 100644 index 000000000..11da52550 --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj new file mode 100644 index 000000000..3aa276e15 --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj @@ -0,0 +1,19 @@ + + + + + + + netstandard2.0 + + + + + + + + + + + + diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogEnrichersUniqueIdModule.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogEnrichersUniqueIdModule.cs new file mode 100644 index 000000000..b287d5417 --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogEnrichersUniqueIdModule.cs @@ -0,0 +1,10 @@ +using LINGYUN.Abp.IdGenerator; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Serilog.Enrichers.UniqueId +{ + [DependsOn(typeof(AbpIdGeneratorModule))] + public class AbpSerilogEnrichersUniqueIdModule : AbpModule + { + } +} diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogUniqueIdConsts.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogUniqueIdConsts.cs new file mode 100644 index 000000000..7fa11d802 --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogUniqueIdConsts.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Serilog.Enrichers.UniqueId +{ + public class AbpSerilogUniqueIdConsts + { + public const string UniqueIdPropertyName = "UniqueId"; + } +} diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/UniqueIdEnricher.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/UniqueIdEnricher.cs new file mode 100644 index 000000000..82d66954b --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/UniqueIdEnricher.cs @@ -0,0 +1,21 @@ +using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.IdGenerator.Snowflake; +using Serilog.Core; +using Serilog.Events; + +namespace LINGYUN.Abp.Serilog.Enrichers.UniqueId +{ + public class UniqueIdEnricher : ILogEventEnricher + { + private readonly static IDistributedIdGenerator _distributedIdGenerator + = SnowflakeIdGenerator.Create(new SnowflakeIdOptions()); + + public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) + { + logEvent.AddOrUpdateProperty( + propertyFactory.CreateProperty( + AbpSerilogUniqueIdConsts.UniqueIdPropertyName, + _distributedIdGenerator.Create())); + } + } +} diff --git a/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/Serilog/UniqueIdLoggerConfigurationExtensions.cs b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/Serilog/UniqueIdLoggerConfigurationExtensions.cs new file mode 100644 index 000000000..91f4b73ed --- /dev/null +++ b/aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/Serilog/UniqueIdLoggerConfigurationExtensions.cs @@ -0,0 +1,16 @@ +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; +using Serilog.Configuration; +using System; + +namespace Serilog +{ + public static class UniqueIdLoggerConfigurationExtensions + { + public static LoggerConfiguration WithUniqueId( + this LoggerEnrichmentConfiguration enrichmentConfiguration) + { + if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); + return enrichmentConfiguration.With(); + } + } +} diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs index 3587c1928..0f6d28ea6 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs @@ -11,6 +11,7 @@ using LINGYUN.Abp.Logging.Serilog.Elasticsearch; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.PermissionManagement.Identity; using LINGYUN.Abp.Serilog.Enrichers.Application; +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; using LINGYUN.Abp.SettingManagement; using LINGYUN.Abp.Sms.Aliyun; using LINGYUN.Abp.TenantManagement; @@ -40,43 +41,44 @@ using Volo.Abp.TenantManagement.EntityFrameworkCore; namespace LY.MicroService.BackendAdmin; [DependsOn( - typeof(AbpSerilogEnrichersApplicationModule), - typeof(AbpAspNetCoreSerilogModule), - typeof(AbpLoggingSerilogElasticsearchModule), - typeof(AbpAuditLoggingElasticsearchModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpSettingManagementApplicationModule), - typeof(AbpSettingManagementHttpApiModule), - typeof(AbpPermissionManagementApplicationModule), - typeof(AbpPermissionManagementHttpApiModule), - typeof(AbpFeatureManagementApplicationModule), - typeof(AbpFeatureManagementHttpApiModule), - typeof(AbpFeatureManagementClientModule), - typeof(AbpAuditingApplicationModule), - typeof(AbpAuditingHttpApiModule), - typeof(AbpTenantManagementApplicationModule), - typeof(AbpTenantManagementHttpApiModule), - typeof(AbpEntityFrameworkCoreMySQLModule), - typeof(AbpIdentityEntityFrameworkCoreModule),// 用户角色权限需要引用包 - typeof(AbpIdentityServerEntityFrameworkCoreModule), // 客户端权限需要引用包 - typeof(AbpTenantManagementEntityFrameworkCoreModule), - typeof(AbpSettingManagementEntityFrameworkCoreModule), - typeof(AbpPermissionManagementDomainIdentityModule), - typeof(AbpPermissionManagementDomainIdentityServerModule), - typeof(AbpPermissionManagementEntityFrameworkCoreModule), - typeof(AbpFeatureManagementEntityFrameworkCoreModule), - typeof(AbpLocalizationManagementEntityFrameworkCoreModule), - typeof(AbpDataDbMigratorModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), - typeof(AbpEmailingExceptionHandlingModule), - typeof(AbpCAPEventBusModule), - typeof(AbpAliyunSmsModule), - typeof(AbpDbFinderMultiTenancyModule), - typeof(AbpCachingStackExchangeRedisModule), - typeof(AbpAspNetCoreHttpOverridesModule), - typeof(AbpLocalizationCultureMapModule), - typeof(AbpAutofacModule) - )] + typeof(AbpSerilogEnrichersApplicationModule), + typeof(AbpSerilogEnrichersUniqueIdModule), + typeof(AbpAspNetCoreSerilogModule), + typeof(AbpLoggingSerilogElasticsearchModule), + typeof(AbpAuditLoggingElasticsearchModule), + typeof(AbpAspNetCoreMvcUiMultiTenancyModule), + typeof(AbpSettingManagementApplicationModule), + typeof(AbpSettingManagementHttpApiModule), + typeof(AbpPermissionManagementApplicationModule), + typeof(AbpPermissionManagementHttpApiModule), + typeof(AbpFeatureManagementApplicationModule), + typeof(AbpFeatureManagementHttpApiModule), + typeof(AbpFeatureManagementClientModule), + typeof(AbpAuditingApplicationModule), + typeof(AbpAuditingHttpApiModule), + typeof(AbpTenantManagementApplicationModule), + typeof(AbpTenantManagementHttpApiModule), + typeof(AbpEntityFrameworkCoreMySQLModule), + typeof(AbpIdentityEntityFrameworkCoreModule),// 用户角色权限需要引用包 + typeof(AbpIdentityServerEntityFrameworkCoreModule), // 客户端权限需要引用包 + typeof(AbpTenantManagementEntityFrameworkCoreModule), + typeof(AbpSettingManagementEntityFrameworkCoreModule), + typeof(AbpPermissionManagementDomainIdentityModule), + typeof(AbpPermissionManagementDomainIdentityServerModule), + typeof(AbpPermissionManagementEntityFrameworkCoreModule), + typeof(AbpFeatureManagementEntityFrameworkCoreModule), + typeof(AbpLocalizationManagementEntityFrameworkCoreModule), + typeof(AbpDataDbMigratorModule), + typeof(AbpAspNetCoreAuthenticationJwtBearerModule), + typeof(AbpEmailingExceptionHandlingModule), + typeof(AbpCAPEventBusModule), + typeof(AbpAliyunSmsModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), + typeof(AbpLocalizationCultureMapModule), + typeof(AbpAutofacModule) + )] public partial class BackendAdminHttpApiHostModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) @@ -89,8 +91,9 @@ public partial class BackendAdminHttpApiHostModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { + context.Services.AddAlwaysAllowAuthorization(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - var configuration = hostingEnvironment.BuildConfiguration(); + var configuration = context.Services.GetConfiguration(); ConfigureDbContext(); ConfigureJsonSerializer(); diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj index 0b2d3ec3c..7290f290a 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj @@ -62,6 +62,7 @@ + diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Properties/launchSettings.json b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Properties/launchSettings.json index ceb66ec05..731195696 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Properties/launchSettings.json +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Properties/launchSettings.json @@ -14,7 +14,7 @@ "launchBrowser": false, "applicationUrl": "http://127.0.0.1:30010", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Production" } } } diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.json b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.json index 4764de687..e113587b1 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.json +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.json @@ -13,7 +13,7 @@ "DotNetCore": "Information" } }, - "Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName" ], + "Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName", "WithUniqueId" ], "WriteTo": [ { "Name": "Console",