diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs index f9093ffaac..b7a02caa5c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Builder public static IApplicationBuilder UseSerilogEnrichers(this IApplicationBuilder app) { return app - .UseMiddleware(); + .UseMiddleware(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogEnrichersOptions.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogEnrichersOptions.cs deleted file mode 100644 index 06453cb61f..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogEnrichersOptions.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Volo.Abp.AspNetCore.Serilog -{ - public class AbpAspNetCoreSerilogEnrichersOptions - { - public string TenantIdEnricherPropertyName { get; set; } - - public string UserIdEnricherPropertyName { get; set; } - - public string ClientIdEnricherPropertyName { get; set; } - - public string CorrelationIdPropertyName { get; set; } - - public AbpAspNetCoreSerilogEnrichersOptions() - { - TenantIdEnricherPropertyName = AbpSerilogEnrichersConsts.TenantIdEnricherPropertyName; - UserIdEnricherPropertyName = AbpSerilogEnrichersConsts.UserIdEnricherPropertyName; - ClientIdEnricherPropertyName = AbpSerilogEnrichersConsts.ClientIdEnricherPropertyName; - CorrelationIdPropertyName = AbpSerilogEnrichersConsts.CorrelationIdPropertyName; - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogModule.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogModule.cs similarity index 90% rename from framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogModule.cs rename to framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogModule.cs index 2b718fcb84..dc8e7c1ce4 100644 --- a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogModule.cs @@ -1,4 +1,3 @@ -using Volo.Abp.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogOptions.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogOptions.cs new file mode 100644 index 0000000000..84f212ff4a --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogOptions.cs @@ -0,0 +1,30 @@ +namespace Volo.Abp.AspNetCore.Serilog +{ + public class AbpAspNetCoreSerilogOptions + { + public AllEnricherPropertyNames EnricherPropertyNames { get; } = new AllEnricherPropertyNames(); + + public class AllEnricherPropertyNames + { + /// + /// Default value: "TenantId". + /// + public string TenantId { get; set; } = "TenantId"; + + /// + /// Default value: "UserId". + /// + public string UserId { get; set; } = "UserId"; + + /// + /// Default value: "ClientId". + /// + public string ClientId { get; set; } = "ClientId"; + + /// + /// Default value: "CorrelationId". + /// + public string CorrelationId { get; set; } = "CorrelationId"; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs deleted file mode 100644 index bf2832b553..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Volo.Abp.AspNetCore.Serilog -{ - public class AbpSerilogEnrichersConsts - { - public const string TenantIdEnricherPropertyName = "TenantId"; - public const string UserIdEnricherPropertyName = "UserId"; - public const string ClientIdEnricherPropertyName = "ClientId"; - public const string CorrelationIdPropertyName = "CorrelationId"; - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/SerilogMiddleware.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogMiddleware.cs similarity index 71% rename from framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/SerilogMiddleware.cs rename to framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogMiddleware.cs index e03bcd5342..8a8f032766 100644 --- a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/SerilogMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogMiddleware.cs @@ -13,20 +13,20 @@ using Volo.Abp.Users; namespace Volo.Abp.AspNetCore.Serilog { - public class SerilogMiddleware : IMiddleware, ITransientDependency + public class AbpSerilogMiddleware : IMiddleware, ITransientDependency { private readonly ICurrentClient _currentClient; private readonly ICurrentTenant _currentTenant; private readonly ICurrentUser _currentUser; private readonly ICorrelationIdProvider _correlationIdProvider; - private readonly AbpAspNetCoreSerilogEnrichersOptions _options; + private readonly AbpAspNetCoreSerilogOptions _options; - public SerilogMiddleware( + public AbpSerilogMiddleware( ICurrentTenant currentTenant, ICurrentUser currentUser, ICurrentClient currentClient, ICorrelationIdProvider correlationIdProvider, - IOptions options) + IOptions options) { _currentTenant = currentTenant; _currentUser = currentUser; @@ -41,23 +41,23 @@ namespace Volo.Abp.AspNetCore.Serilog if (_currentTenant?.Id != null) { - enrichers.Add(new PropertyEnricher(_options.TenantIdEnricherPropertyName, _currentTenant.Id)); + enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.TenantId, _currentTenant.Id)); } if (_currentUser?.Id != null) { - enrichers.Add(new PropertyEnricher(_options.UserIdEnricherPropertyName, _currentUser.Id)); + enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.UserId, _currentUser.Id)); } if (_currentClient?.Id != null) { - enrichers.Add(new PropertyEnricher(_options.ClientIdEnricherPropertyName, _currentClient.Id)); + enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.ClientId, _currentClient.Id)); } var correlationId = _correlationIdProvider.Get(); if (!string.IsNullOrEmpty(correlationId)) { - enrichers.Add(new PropertyEnricher(_options.CorrelationIdPropertyName, correlationId)); + enrichers.Add(new PropertyEnricher(_options.EnricherPropertyNames.CorrelationId, correlationId)); } using (LogContext.Push(enrichers.ToArray())) diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs index bc45eb7c51..0a7a189a35 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs @@ -22,14 +22,14 @@ namespace Volo.Abp.AspNetCore.Serilog private readonly string _testTenantName = "acme"; private readonly AbpAspNetCoreMultiTenancyOptions _tenancyOptions; - private readonly AbpAspNetCoreSerilogEnrichersOptions _serilogEnrichersOptions; + private readonly AbpAspNetCoreSerilogOptions _serilogOptions; private readonly ILogger _logger; public Serilog_Enrichers_Tests() { _tenancyOptions = ServiceProvider.GetRequiredService>().Value; - _serilogEnrichersOptions = - ServiceProvider.GetRequiredService>().Value; + _serilogOptions = + ServiceProvider.GetRequiredService>().Value; _logger = ServiceProvider.GetRequiredService>(); } @@ -56,7 +56,7 @@ namespace Volo.Abp.AspNetCore.Serilog var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); executedLogEvent.ShouldNotBeNull(); - executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.TenantIdEnricherPropertyName) + executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.TenantId) .ShouldBe(false); } @@ -71,9 +71,9 @@ namespace Volo.Abp.AspNetCore.Serilog var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); executedLogEvent.ShouldNotBeNull(); - executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.TenantIdEnricherPropertyName) + executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.TenantId) .ShouldBe(true); - ((ScalarValue) executedLogEvent.Properties[_serilogEnrichersOptions.TenantIdEnricherPropertyName]).Value + ((ScalarValue) executedLogEvent.Properties[_serilogOptions.EnricherPropertyNames.TenantId]).Value .ShouldBe(_testTenantId); } @@ -87,10 +87,10 @@ namespace Volo.Abp.AspNetCore.Serilog executedLogEvent.ShouldNotBeNull(); - executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.CorrelationIdPropertyName) + executedLogEvent.Properties.ContainsKey(_serilogOptions.EnricherPropertyNames.CorrelationId) .ShouldNotBeNull(); - ((ScalarValue) executedLogEvent.Properties[_serilogEnrichersOptions.CorrelationIdPropertyName]).Value + ((ScalarValue) executedLogEvent.Properties[_serilogOptions.EnricherPropertyNames.CorrelationId]).Value .ShouldBe(result); } }