37 changed files with 387 additions and 176 deletions
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -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> |
|||
@ -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> |
|||
@ -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)); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace LINGYUN.Abp.IdGenerator; |
|||
|
|||
public interface IDistributedIdGenerator |
|||
{ |
|||
long Create(); |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
namespace LINGYUN.Abp.RealTime |
|||
{ |
|||
public interface ISnowflakeIdrGenerator |
|||
{ |
|||
long Create(); |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait /> |
|||
</Weavers> |
|||
@ -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> |
|||
@ -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> |
|||
@ -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 |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace LINGYUN.Abp.Serilog.Enrichers.UniqueId |
|||
{ |
|||
public class AbpSerilogUniqueIdConsts |
|||
{ |
|||
public const string UniqueIdPropertyName = "UniqueId"; |
|||
} |
|||
} |
|||
@ -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())); |
|||
} |
|||
} |
|||
} |
|||
@ -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>(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue