Browse Source

feat(logging): enables more accurate ES retrieval for logging

pull/448/head
cKey 4 years ago
parent
commit
dc0184f582
  1. 14
      aspnet-core/LINGYUN.MicroService.All.sln
  2. 31
      aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs
  3. 21
      aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchSecurityLogManager.cs
  4. 1
      aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/Logging/Dto/LogFieldDto.cs
  5. 7
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs
  6. 3
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj
  7. 4
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/AbpIMModule.cs
  8. 11
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs
  9. 3
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xml
  10. 30
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xsd
  11. 15
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN.Abp.IdGenerator.csproj
  12. 17
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/AbpIdGeneratorModule.cs
  13. 6
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/IDistributedIdGenerator.cs
  14. 56
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdGenerator.cs
  15. 29
      aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN/Abp/IdGenerator/Snowflake/SnowflakeIdOptions.cs
  16. 3
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj
  17. 4
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
  18. 13
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs
  19. 11
      aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs
  20. 7
      aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs
  21. 24
      aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs
  22. 1
      aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj
  23. 3
      aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/AbpLoggingSerilogElasticsearchMapperProfile.cs
  24. 52
      aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogElasticsearchLoggingManager.cs
  25. 4
      aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN/Abp/AuditLogging/Serilog/Elasticsearch/SerilogField.cs
  26. 1
      aspnet-core/modules/logging/LINGYUN.Abp.Logging/LINGYUN/Abp/AuditLogging/LogField.cs
  27. 3
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xml
  28. 30
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xsd
  29. 19
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj
  30. 10
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogEnrichersUniqueIdModule.cs
  31. 7
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/AbpSerilogUniqueIdConsts.cs
  32. 21
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN/Abp/Serilog/Enrichers/UniqueId/UniqueIdEnricher.cs
  33. 16
      aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/Serilog/UniqueIdLoggerConfigurationExtensions.cs
  34. 5
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs
  35. 1
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj
  36. 2
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Properties/launchSettings.json
  37. 2
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.json

14
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}

31
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)
{

21
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)
{

1
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; }

7
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<IUserOnlineChanger>();
protected ISnowflakeIdrGenerator SnowflakeIdrGenerator => LazyServiceProvider.LazyGetRequiredService<ISnowflakeIdrGenerator>();
protected IDistributedIdGenerator DistributedIdGenerator => LazyServiceProvider.LazyGetRequiredService<IDistributedIdGenerator>();
protected IExceptionToErrorInfoConverter ErrorInfoConverter => LazyServiceProvider.LazyGetRequiredService<IExceptionToErrorInfoConverter>();
@ -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())

3
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
@ -22,6 +22,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.IdGenerator\LINGYUN.Abp.IdGenerator.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj" />
</ItemGroup>

4
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)

11
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<string> 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>(chatMessage);

3
aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

15
aspnet-core/modules/common/LINGYUN.Abp.IdGenerator/LINGYUN.Abp.IdGenerator.csproj

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Core" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
</Project>

17
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<IDistributedIdGenerator>(SnowflakeIdGenerator.Create(snowflakeIdOptions));
}
}

6
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();
}

56
aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs → 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<SnowflakeIdOptions> 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)
{
var idGenerator = new SnowflakeIdGenerator(options)
{
Sequence = sequence;
MaxWorkerId = -1L ^ (-1L << Options.WorkerIdBits);
MaxDatacenterId = -1L ^ (-1L << Options.DatacenterIdBits);
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");
WorkerId = workerId;
DatacenterId = datacenterId;
idGenerator.WorkerId = workerId;
idGenerator.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()
{

29
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
{
/// <summary>
/// 机器Id长度
/// </summary>
public int WorkerIdBits { get; set; }
/// <summary>
/// 机房Id长度
/// </summary>
public int DatacenterIdBits { get; set; }
/// <summary>
/// 12bit 的序号
/// </summary>
public long Sequence { get; set; }
/// <summary>
/// 每秒生成Id的数量
/// </summary>
public int SequenceBits { get; set; }
public SnowflakeIdOptions()
{
WorkerIdBits = 5;
DatacenterIdBits = 5;
Sequence = 0L;
SequenceBits = 12;
}
}

3
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
@ -16,6 +16,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.IdGenerator\LINGYUN.Abp.IdGenerator.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj" />
</ItemGroup>

4
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

13
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
/// </summary>
public IDistributedEventBus DistributedEventBus { get; }
/// <summary>
/// Reference to <see cref="IMessageIdGenerator"/>.
/// Reference to <see cref="IDistributedIdGenerator"/>.
/// </summary>
protected ISnowflakeIdrGenerator SnowflakeIdGenerator { get; }
protected IDistributedIdGenerator DistributedIdGenerator { get; }
protected AbpNotificationOptions Options { get; }
public NotificationSender(
IDistributedEventBus distributedEventBus,
ISnowflakeIdrGenerator snowflakeIdrGenerator,
IDistributedIdGenerator distributedIdGenerator,
IOptions<AbpNotificationOptions> options)
{
Options = options.Value;
DistributedEventBus = distributedEventBus;
SnowflakeIdGenerator = snowflakeIdrGenerator;
DistributedIdGenerator = distributedIdGenerator;
Logger = NullLogger<NotificationSender>.Instance;
}
@ -79,7 +80,7 @@ namespace LINGYUN.Abp.Notifications
{
var eto = new NotificationEto<NotificationData>(data)
{
Id = SnowflakeIdGenerator.Create(),
Id = DistributedIdGenerator.Create(),
TenantId = tenantId,
Users = users?.ToList(),
Name = name,

11
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<SnowflakeIdrGenerator>()
.Initialize();
}
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs

@ -1,7 +0,0 @@
namespace LINGYUN.Abp.RealTime
{
public interface ISnowflakeIdrGenerator
{
long Create();
}
}

24
aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs

@ -1,24 +0,0 @@
namespace LINGYUN.Abp.RealTime
{
public class SnowflakeIdOptions
{
/// <summary>
/// 机器Id长度
/// </summary>
public int WorkerIdBits { get; set; }
/// <summary>
/// 机房Id长度
/// </summary>
public int DatacenterIdBits { get; set; }
/// <summary>
/// 每秒生成Id的数量
/// </summary>
public int SequenceBits { get; set; }
public SnowflakeIdOptions()
{
WorkerIdBits = 5;
DatacenterIdBits = 5;
SequenceBits = 12;
}
}
}

1
aspnet-core/modules/logging/LINGYUN.Abp.Logging.Serilog.Elasticsearch/LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj

@ -18,6 +18,7 @@
<ProjectReference Include="..\..\elasticsearch\LINGYUN.Abp.Elasticsearch\LINGYUN.Abp.Elasticsearch.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Logging\LINGYUN.Abp.Logging.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Serilog.Enrichers.Application\LINGYUN.Abp.Serilog.Enrichers.Application.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Serilog.Enrichers.UniqueId\LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj" />
</ItemGroup>
</Project>

3
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<SerilogException, LogException>();
CreateMap<SerilogField, LogField>();
CreateMap<SerilogField, LogField>()
.ForMember(log => log.Id, map => map.MapFrom(slog => slog.UniqueId.ToString()));
CreateMap<SerilogInfo, LogInfo>();
}
}

52
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<SerilogInfo>((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)
{

4
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; }

1
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; }

3
aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait />
</Weavers>

30
aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

19
aspnet-core/modules/logging/LINGYUN.Abp.Serilog.Enrichers.UniqueId/LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="$(SerilogPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.IdGenerator\LINGYUN.Abp.IdGenerator.csproj" />
</ItemGroup>
</Project>

10
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
{
}
}

7
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";
}
}

21
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()));
}
}
}

16
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<UniqueIdEnricher>();
}
}
}

5
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;
@ -41,6 +42,7 @@ namespace LY.MicroService.BackendAdmin;
[DependsOn(
typeof(AbpSerilogEnrichersApplicationModule),
typeof(AbpSerilogEnrichersUniqueIdModule),
typeof(AbpAspNetCoreSerilogModule),
typeof(AbpLoggingSerilogElasticsearchModule),
typeof(AbpAuditLoggingElasticsearchModule),
@ -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();

1
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj

@ -62,6 +62,7 @@
<ProjectReference Include="..\..\modules\localization\LINGYUN.Abp.Localization.CultureMap\LINGYUN.Abp.Localization.CultureMap.csproj" />
<ProjectReference Include="..\..\modules\logging\LINGYUN.Abp.Logging.Serilog.Elasticsearch\LINGYUN.Abp.Logging.Serilog.Elasticsearch.csproj" />
<ProjectReference Include="..\..\modules\logging\LINGYUN.Abp.Serilog.Enrichers.Application\LINGYUN.Abp.Serilog.Enrichers.Application.csproj" />
<ProjectReference Include="..\..\modules\logging\LINGYUN.Abp.Serilog.Enrichers.UniqueId\LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj" />
<ProjectReference Include="..\..\modules\lt\LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore\LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\identity\LINGYUN.Abp.PermissionManagement.Domain.Identity\LINGYUN.Abp.PermissionManagement.Domain.Identity.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Sms.Aliyun\LINGYUN.Abp.Sms.Aliyun.csproj" />

2
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"
}
}
}

2
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",

Loading…
Cancel
Save