From cfa4d09e36d29371c86d94236cb5aebfe9debf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Tue, 7 Jan 2020 23:44:47 +0300 Subject: [PATCH 01/11] Create Volo.Abp.AspNetCore.Serilog package. --- framework/Volo.Abp.sln | 9 ++- ...CoreSerilogApplicationBuilderExtensions.cs | 13 ++++ .../Volo.Abp.AspNetCore.Serilog.csproj | 27 +++++++ .../AspNetCore/Serilog/AbpSerilogModule.cs | 14 ++++ .../AspNetCore/Serilog/SerilogMiddleware.cs | 70 +++++++++++++++++++ 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Volo.Abp.AspNetCore.Serilog.csproj create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogModule.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/SerilogMiddleware.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 088a9437a8..b9a27d757f 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28922.388 MinimumVisualStudioVersion = 10.0.40219.1 @@ -256,6 +256,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Minify", "src\Volo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Minify.Tests", "test\Volo.Abp.Minify.Tests\Volo.Abp.Minify.Tests.csproj", "{E69182B3-350A-43F5-A935-5EBBEBECEF97}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Serilog", "src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj", "{3B801003-BE74-49ED-9749-DA5E99F45EBF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -762,6 +764,10 @@ Global {E69182B3-350A-43F5-A935-5EBBEBECEF97}.Debug|Any CPU.Build.0 = Debug|Any CPU {E69182B3-350A-43F5-A935-5EBBEBECEF97}.Release|Any CPU.ActiveCfg = Release|Any CPU {E69182B3-350A-43F5-A935-5EBBEBECEF97}.Release|Any CPU.Build.0 = Release|Any CPU + {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -892,6 +898,7 @@ Global {73559227-EBF0-475F-835B-1FF0CD9132AA} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {928DC30D-C078-4BB4-A9F8-FE7252C67DC6} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {E69182B3-350A-43F5-A935-5EBBEBECEF97} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {3B801003-BE74-49ED-9749-DA5E99F45EBF} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} 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 new file mode 100644 index 0000000000..f9093ffaac --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Microsoft/AspNetCore/Builder/AbpAspNetCoreSerilogApplicationBuilderExtensions.cs @@ -0,0 +1,13 @@ +using Volo.Abp.AspNetCore.Serilog; + +namespace Microsoft.AspNetCore.Builder +{ + public static class AbpAspNetCoreSerilogApplicationBuilderExtensions + { + public static IApplicationBuilder UseSerilogEnrichers(this IApplicationBuilder app) + { + return app + .UseMiddleware(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Serilog/Volo.Abp.AspNetCore.Serilog.csproj b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo.Abp.AspNetCore.Serilog.csproj new file mode 100644 index 0000000000..f450e04423 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo.Abp.AspNetCore.Serilog.csproj @@ -0,0 +1,27 @@ + + + + + + netcoreapp3.1 + Volo.Abp.AspNetCore.Serilog + Volo.Abp.AspNetCore.Serilog + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + true + Library + + + + + + + + + + + + + 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/AbpSerilogModule.cs new file mode 100644 index 0000000000..5012d54e30 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogModule.cs @@ -0,0 +1,14 @@ +using Volo.Abp.AspNetCore; +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.Serilog +{ + [DependsOn( + typeof(AbpMultiTenancyModule), + typeof(AbpAspNetCoreModule) + )] + public class AbpSerilogModule : AbpModule + { + } +} \ 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/SerilogMiddleware.cs new file mode 100644 index 0000000000..10bbdb188f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/SerilogMiddleware.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Serilog.Context; +using Serilog.Core; +using Serilog.Core.Enrichers; +using Volo.Abp.Clients; +using Volo.Abp.DependencyInjection; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Tracing; +using Volo.Abp.Users; + +namespace Volo.Abp.AspNetCore.Serilog +{ + public class SerilogMiddleware : IMiddleware, ITransientDependency + { + private const string TenantEnricherPropertyName = "TenantId"; + private const string UserEnricherPropertyName = "UserId"; + private const string ClientEnricherPropertyName = "ClientId"; + private const string CorrelationIdPropertyName = "CorrelationId"; + + private readonly ICurrentClient _currentClient; + private readonly ICurrentTenant _currentTenant; + private readonly ICurrentUser _currentUser; + private readonly ICorrelationIdProvider _correlationIdProvider; + + public SerilogMiddleware( + ICurrentTenant currentTenant, + ICurrentUser currentUser, + ICurrentClient currentClient, + ICorrelationIdProvider correlationIdProvider) + { + _currentTenant = currentTenant; + _currentUser = currentUser; + _currentClient = currentClient; + _correlationIdProvider = correlationIdProvider; + } + + public async Task InvokeAsync(HttpContext context, RequestDelegate next) + { + var enrichers = new List(); + + if (_currentTenant?.Id != null) + { + enrichers.Add(new PropertyEnricher(TenantEnricherPropertyName, _currentTenant.Id)); + } + + if (_currentUser?.Id != null) + { + enrichers.Add(new PropertyEnricher(UserEnricherPropertyName, _currentUser.Id)); + } + + if (_currentClient?.Id != null) + { + enrichers.Add(new PropertyEnricher(ClientEnricherPropertyName, _currentClient.Id)); + } + + var correlationId = _correlationIdProvider.Get(); + if (!string.IsNullOrEmpty(correlationId)) + { + enrichers.Add(new PropertyEnricher(CorrelationIdPropertyName, correlationId)); + } + + using (LogContext.Push(enrichers.ToArray())) + { + await next(context).ConfigureAwait(false); + } + } + } +} \ No newline at end of file From c57281570177e91d4f80a00ebcf8f58d5f9cda15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Wed, 8 Jan 2020 07:41:56 +0300 Subject: [PATCH 02/11] Update application template UseSerilogEnrichers. --- .../MyCompanyName.MyProjectName.HttpApi.Host.csproj | 1 + .../MyProjectNameHttpApiHostModule.cs | 5 ++++- ...yCompanyName.MyProjectName.HttpApi.HostWithIds.csproj | 1 + .../MyProjectNameHttpApiHostModule.cs | 5 ++++- .../MyCompanyName.MyProjectName.IdentityServer.csproj | 2 ++ .../MyProjectNameIdentityServerModule.cs | 5 ++++- .../MyCompanyName.MyProjectName.Web.Host.csproj | 2 ++ .../MyProjectNameWebModule.cs | 6 ++++-- .../MyCompanyName.MyProjectName.Web.csproj | 1 + .../MyProjectNameWebModule.cs | 9 ++++----- 10 files changed, 27 insertions(+), 10 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj index 19435bb1fa..173d10bbc2 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj @@ -20,6 +20,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index 59ba519ce4..3db35cd20b 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -15,6 +15,7 @@ using Microsoft.OpenApi.Models; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.Caching; using Volo.Abp.Localization; @@ -28,7 +29,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpAutofacModule), typeof(AbpAspNetCoreMvcUiMultiTenancyModule), typeof(MyProjectNameApplicationModule), - typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule) + typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule), + typeof(AbpSerilogModule) )] public class MyProjectNameHttpApiHostModule : AbpModule { @@ -178,6 +180,7 @@ namespace MyCompanyName.MyProjectName }); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj index 038e2e4016..f59176e5af 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj @@ -20,6 +20,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs index a60d2ddb35..73a9d01be6 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs @@ -18,6 +18,7 @@ using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -34,7 +35,8 @@ namespace MyCompanyName.MyProjectName typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), - typeof(AbpAccountWebIdentityServerModule) + typeof(AbpAccountWebIdentityServerModule), + typeof(AbpSerilogModule) )] public class MyProjectNameHttpApiHostModule : AbpModule { @@ -172,6 +174,7 @@ namespace MyCompanyName.MyProjectName }); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj index aecc6831be..e040f9642d 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj @@ -43,6 +43,8 @@ + + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs index 2e2211791e..117386e588 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs @@ -18,6 +18,7 @@ using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Auditing; using Volo.Abp.Autofac; using Volo.Abp.BackgroundJobs; @@ -35,7 +36,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpAccountWebIdentityServerModule), typeof(AbpAccountApplicationModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), - typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule) + typeof(MyProjectNameEntityFrameworkCoreDbMigrationsModule), + typeof(AbpSerilogModule) )] public class MyProjectNameIdentityServerModule : AbpModule { @@ -149,6 +151,7 @@ namespace MyCompanyName.MyProjectName app.UseAuthorization(); app.UseAbpRequestLocalization(); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index 66864acc82..ecdd1446fa 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -29,6 +29,8 @@ + + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs index 28afed0c7c..c30a3b5d88 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs @@ -22,6 +22,7 @@ using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; @@ -49,7 +50,8 @@ namespace MyCompanyName.MyProjectName.Web typeof(AbpFeatureManagementWebModule), typeof(AbpHttpClientIdentityModelModule), typeof(AbpIdentityWebModule), - typeof(AbpTenantManagementWebModule) + typeof(AbpTenantManagementWebModule), + typeof(AbpSerilogModule) )] public class MyProjectNameWebModule : AbpModule { @@ -241,7 +243,7 @@ namespace MyCompanyName.MyProjectName.Web }); app.UseAuditing(); - + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj index 9540447c74..6cf7d25498 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj @@ -47,6 +47,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs index 87626719f3..cd27c9ece2 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs @@ -23,6 +23,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.FeatureManagement; @@ -47,7 +48,8 @@ namespace MyCompanyName.MyProjectName.Web typeof(AbpAccountWebIdentityServerModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), - typeof(AbpTenantManagementWebModule) + typeof(AbpTenantManagementWebModule), + typeof(AbpSerilogModule) )] public class MyProjectNameWebModule : AbpModule { @@ -198,7 +200,6 @@ namespace MyCompanyName.MyProjectName.Web { app.UseErrorPage(); } - app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); @@ -208,18 +209,16 @@ namespace MyCompanyName.MyProjectName.Web { app.UseMultiTenancy(); } - app.UseIdentityServer(); app.UseAuthorization(); app.UseAbpRequestLocalization(); - app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API"); }); - app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } From 3028b1a431c06894068382aa3d2af925935d7db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Wed, 8 Jan 2020 07:54:17 +0300 Subject: [PATCH 03/11] Update module template UseSerilogEnrichers. --- .../MyCompanyName.MyProjectName.HttpApi.Host.csproj | 1 + .../MyProjectNameHttpApiHostModule.cs | 5 ++++- .../MyCompanyName.MyProjectName.IdentityServer.csproj | 1 + .../MyProjectNameIdentityServerModule.cs | 5 ++++- .../MyCompanyName.MyProjectName.Web.Host.csproj | 6 ++++++ .../MyProjectNameWebHostModule.cs | 6 ++++-- .../MyCompanyName.MyProjectName.Web.Unified.csproj | 1 + .../MyProjectNameWebUnifiedModule.cs | 5 ++++- 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj index fe10668840..07979b3f63 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj @@ -19,6 +19,7 @@ + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index f48706663e..972ccc9708 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -15,6 +15,7 @@ using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; using Volo.Abp.Caching; @@ -39,7 +40,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpAuditLoggingEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), - typeof(AbpSettingManagementEntityFrameworkCoreModule) + typeof(AbpSettingManagementEntityFrameworkCoreModule), + typeof(AbpSerilogModule) )] public class MyProjectNameHttpApiHostModule : AbpModule { @@ -166,6 +168,7 @@ namespace MyCompanyName.MyProjectName options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API"); }); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj index b25ce4b603..062dceabaf 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj @@ -21,6 +21,7 @@ + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs index 5f0f80c05e..7205fdf225 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs @@ -17,6 +17,7 @@ using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Auditing; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; @@ -66,7 +67,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), - typeof(MyProjectNameApplicationContractsModule) + typeof(MyProjectNameApplicationContractsModule), + typeof(AbpSerilogModule) )] public class MyProjectNameIdentityServerModule : AbpModule { @@ -189,6 +191,7 @@ namespace MyCompanyName.MyProjectName options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API"); }); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); SeedData(context); diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index 663a908ad8..cacefbdb7c 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -51,4 +51,10 @@ + + + ..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Serilog\bin\Debug\netcoreapp3.1\Volo.Abp.AspNetCore.Serilog.dll + + + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs index 473bdab2cf..cabb843736 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs @@ -21,6 +21,7 @@ using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; @@ -55,7 +56,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpTenantManagementWebModule), typeof(AbpTenantManagementHttpApiClientModule), typeof(AbpFeatureManagementHttpApiClientModule), - typeof(AbpPermissionManagementHttpApiClientModule) + typeof(AbpPermissionManagementHttpApiClientModule), + typeof(AbpSerilogModule) )] public class MyProjectNameWebHostModule : AbpModule { @@ -249,7 +251,7 @@ namespace MyCompanyName.MyProjectName }); app.UseAuditing(); - + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); } } diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj index 1099836b9c..35fe11e53d 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj @@ -17,6 +17,7 @@ + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyProjectNameWebUnifiedModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyProjectNameWebUnifiedModule.cs index 8390297a9f..ea653ca4a1 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyProjectNameWebUnifiedModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyProjectNameWebUnifiedModule.cs @@ -12,6 +12,7 @@ using Volo.Abp.Account; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; +using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; using Volo.Abp.Data; @@ -56,7 +57,8 @@ namespace MyCompanyName.MyProjectName typeof(AbpTenantManagementWebModule), typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementEntityFrameworkCoreModule), - typeof(AbpAspNetCoreMvcUiBasicThemeModule) + typeof(AbpAspNetCoreMvcUiBasicThemeModule), + typeof(AbpSerilogModule) )] public class MyProjectNameWebUnifiedModule : AbpModule { @@ -137,6 +139,7 @@ namespace MyCompanyName.MyProjectName app.UseAbpRequestLocalization(); app.UseAuditing(); + app.UseSerilogEnrichers(); app.UseMvcWithDefaultRouteAndArea(); using (var scope = context.ServiceProvider.CreateScope()) From 3c479b952429898a1dda770a00d3c65291d1e232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Thu, 9 Jan 2020 00:20:27 +0300 Subject: [PATCH 04/11] Adding AbpAspNetCoreSerilogEnrichersOptions. --- .../AbpAspNetCoreSerilogEnrichersOptions.cs | 21 +++++++++++++++++++ .../Serilog/AbpSerilogEnrichersConsts.cs | 10 +++++++++ .../AspNetCore/Serilog/SerilogMiddleware.cs | 19 ++++++++--------- 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogEnrichersOptions.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs 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 new file mode 100644 index 0000000000..06453cb61f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpAspNetCoreSerilogEnrichersOptions.cs @@ -0,0 +1,21 @@ +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/AbpSerilogEnrichersConsts.cs b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs new file mode 100644 index 0000000000..bf2832b553 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogEnrichersConsts.cs @@ -0,0 +1,10 @@ +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/SerilogMiddleware.cs index 10bbdb188f..e03bcd5342 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/SerilogMiddleware.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Serilog.Context; using Serilog.Core; using Serilog.Core.Enrichers; @@ -14,26 +15,24 @@ namespace Volo.Abp.AspNetCore.Serilog { public class SerilogMiddleware : IMiddleware, ITransientDependency { - private const string TenantEnricherPropertyName = "TenantId"; - private const string UserEnricherPropertyName = "UserId"; - private const string ClientEnricherPropertyName = "ClientId"; - private const string CorrelationIdPropertyName = "CorrelationId"; - private readonly ICurrentClient _currentClient; private readonly ICurrentTenant _currentTenant; private readonly ICurrentUser _currentUser; private readonly ICorrelationIdProvider _correlationIdProvider; + private readonly AbpAspNetCoreSerilogEnrichersOptions _options; public SerilogMiddleware( ICurrentTenant currentTenant, ICurrentUser currentUser, ICurrentClient currentClient, - ICorrelationIdProvider correlationIdProvider) + ICorrelationIdProvider correlationIdProvider, + IOptions options) { _currentTenant = currentTenant; _currentUser = currentUser; _currentClient = currentClient; _correlationIdProvider = correlationIdProvider; + _options = options.Value; } public async Task InvokeAsync(HttpContext context, RequestDelegate next) @@ -42,23 +41,23 @@ namespace Volo.Abp.AspNetCore.Serilog if (_currentTenant?.Id != null) { - enrichers.Add(new PropertyEnricher(TenantEnricherPropertyName, _currentTenant.Id)); + enrichers.Add(new PropertyEnricher(_options.TenantIdEnricherPropertyName, _currentTenant.Id)); } if (_currentUser?.Id != null) { - enrichers.Add(new PropertyEnricher(UserEnricherPropertyName, _currentUser.Id)); + enrichers.Add(new PropertyEnricher(_options.UserIdEnricherPropertyName, _currentUser.Id)); } if (_currentClient?.Id != null) { - enrichers.Add(new PropertyEnricher(ClientEnricherPropertyName, _currentClient.Id)); + enrichers.Add(new PropertyEnricher(_options.ClientIdEnricherPropertyName, _currentClient.Id)); } var correlationId = _correlationIdProvider.Get(); if (!string.IsNullOrEmpty(correlationId)) { - enrichers.Add(new PropertyEnricher(CorrelationIdPropertyName, correlationId)); + enrichers.Add(new PropertyEnricher(_options.CorrelationIdPropertyName, correlationId)); } using (LogContext.Push(enrichers.ToArray())) From beecc1995732e37f76c49e9274dc522df541d512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Thu, 9 Jan 2020 10:39:49 +0300 Subject: [PATCH 05/11] Add test project. --- framework/Volo.Abp.sln | 7 ++ .../Volo.Abp.AspNetCore.Serilog.Tests.csproj | 24 +++++ .../AspNetCore/App/AbpSerilogTestModule.cs | 39 ++++++++ .../Volo/Abp/AspNetCore/App/CollectingSink.cs | 19 ++++ .../AspNetCore/App/SerilogTestController.cs | 27 ++++++ .../Volo/Abp/AspNetCore/App/Startup.cs | 20 ++++ .../AspNetCore/Serilog/AbpSerilogTestBase.cs | 31 ++++++ .../Serilog/Serilog_Enrichers_Tests.cs | 97 +++++++++++++++++++ 8 files changed, 264 insertions(+) create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo.Abp.AspNetCore.Serilog.Tests.csproj create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/CollectingSink.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/SerilogTestController.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index b9a27d757f..b731aff187 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -258,6 +258,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Minify.Tests", "te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Serilog", "src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj", "{3B801003-BE74-49ED-9749-DA5E99F45EBF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Serilog.Tests", "test\Volo.Abp.AspNetCore.Serilog.Tests\Volo.Abp.AspNetCore.Serilog.Tests.csproj", "{9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -768,6 +770,10 @@ Global {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Release|Any CPU.ActiveCfg = Release|Any CPU {3B801003-BE74-49ED-9749-DA5E99F45EBF}.Release|Any CPU.Build.0 = Release|Any CPU + {9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -899,6 +905,7 @@ Global {928DC30D-C078-4BB4-A9F8-FE7252C67DC6} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {E69182B3-350A-43F5-A935-5EBBEBECEF97} = {447C8A77-E5F0-4538-8687-7383196D04EA} {3B801003-BE74-49ED-9749-DA5E99F45EBF} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {9CAA07ED-FE5C-4427-A6FA-6C6CB5B4CC62} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo.Abp.AspNetCore.Serilog.Tests.csproj b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo.Abp.AspNetCore.Serilog.Tests.csproj new file mode 100644 index 0000000000..740c57949d --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo.Abp.AspNetCore.Serilog.Tests.csproj @@ -0,0 +1,24 @@ + + + + + + netcoreapp3.1 + Volo.Abp.AspNetCore.Serilog.Tests + Volo.Abp.AspNetCore.Serilog.Tests + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs new file mode 100644 index 0000000000..64ac0d76bc --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Serilog; +using Volo.Abp.AspNetCore.TestBase; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.App +{ + [DependsOn( + typeof(AbpAspNetCoreTestBaseModule), + typeof(AbpAspNetCoreMvcModule), + typeof(AbpAspNetCoreMultiTenancyModule), + typeof(AbpSerilogModule), + typeof(AbpAutofacModule) + )] + public class AbpSerilogTestModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => { options.IsEnabled = true; }); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + + app.UseCorrelationId(); + app.UseRouting(); + app.UseAuthorization(); + app.UseMultiTenancy(); + app.UseAuditing(); + app.UseSerilogEnrichers(); + app.UseMvcWithDefaultRouteAndArea(); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/CollectingSink.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/CollectingSink.cs new file mode 100644 index 0000000000..fe403e02ef --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/CollectingSink.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Linq; +using Serilog.Core; +using Serilog.Events; + +namespace Volo.Abp.AspNetCore.App +{ + public class CollectingSink : ILogEventSink + { + public List Events { get; } = new List(); + + public LogEvent SingleEvent => Events.Single(); + + public void Emit(LogEvent logEvent) + { + Events.Add(logEvent); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/SerilogTestController.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/SerilogTestController.cs new file mode 100644 index 0000000000..972af4c801 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/SerilogTestController.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Tracing; + +namespace Volo.Abp.AspNetCore.App +{ + public class SerilogTestController : AbpController + { + private readonly ICorrelationIdProvider _correlationIdProvider; + + public SerilogTestController(ICorrelationIdProvider correlationIdProvider) + { + _correlationIdProvider = correlationIdProvider; + } + + public ActionResult Index() + { + return Content("Index-Result"); + } + + public ActionResult CorrelationId() + { + return Content(_correlationIdProvider.Get()); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs new file mode 100644 index 0000000000..a1a58100d5 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Volo.Abp.AspNetCore.App +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddApplication(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env,ILoggerFactory loggerFactory) + { + app.InitializeApplication(); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs new file mode 100644 index 0000000000..96a13ac45b --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs @@ -0,0 +1,31 @@ +using System.Linq; +using Microsoft.Extensions.Hosting; +using Serilog; +using Serilog.Events; +using Volo.Abp.AspNetCore.App; + +namespace Volo.Abp.AspNetCore.Serilog +{ + public class AbpSerilogTestBase : AbpAspNetCoreTestBase + { + protected readonly CollectingSink CollectingSink = new CollectingSink(); + + protected override IHostBuilder CreateHostBuilder() + { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.Sink(CollectingSink) + .CreateLogger(); + + return base.CreateHostBuilder() + .UseSerilog(); + } + + protected LogEvent GetLogEvent(string text) + { + return CollectingSink.Events.FirstOrDefault(m => m.MessageTemplate.Text == text); + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..bc45eb7c51 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs @@ -0,0 +1,97 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Serilog.Events; +using Shouldly; +using Volo.Abp.AspNetCore.App; +using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.MultiTenancy; +using Volo.Abp.MultiTenancy.ConfigurationStore; +using Xunit; + +namespace Volo.Abp.AspNetCore.Serilog +{ + public class Serilog_Enrichers_Tests : AbpSerilogTestBase + { + private const string ExecutedEndpointLogEventText = "Executed endpoint '{EndpointName}'"; + + private readonly Guid _testTenantId = Guid.NewGuid(); + private readonly string _testTenantName = "acme"; + + private readonly AbpAspNetCoreMultiTenancyOptions _tenancyOptions; + private readonly AbpAspNetCoreSerilogEnrichersOptions _serilogEnrichersOptions; + private readonly ILogger _logger; + + public Serilog_Enrichers_Tests() + { + _tenancyOptions = ServiceProvider.GetRequiredService>().Value; + _serilogEnrichersOptions = + ServiceProvider.GetRequiredService>().Value; + _logger = ServiceProvider.GetRequiredService>(); + } + + protected override IHostBuilder CreateHostBuilder() + { + return base.CreateHostBuilder().ConfigureServices(services => + { + services.Configure(options => + { + options.Tenants = new[] + { + new TenantConfiguration(_testTenantId, _testTenantName) + }; + }); + }); + } + + [Fact] + public async Task TenantId_Not_Set_Test() + { + var url = GetUrl(nameof(SerilogTestController.Index)); + var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); + + var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); + + executedLogEvent.ShouldNotBeNull(); + executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.TenantIdEnricherPropertyName) + .ShouldBe(false); + } + + [Fact] + public async Task TenantId_Set_Test() + { + var url = + GetUrl(nameof(SerilogTestController.Index)) + + $"?{_tenancyOptions.TenantKey}={_testTenantName}"; + var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); + + var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); + + executedLogEvent.ShouldNotBeNull(); + executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.TenantIdEnricherPropertyName) + .ShouldBe(true); + ((ScalarValue) executedLogEvent.Properties[_serilogEnrichersOptions.TenantIdEnricherPropertyName]).Value + .ShouldBe(_testTenantId); + } + + [Fact] + public async Task CorrelationId_Enrichers_Test() + { + var url = GetUrl(nameof(SerilogTestController.CorrelationId)); + var result = await GetResponseAsStringAsync(url).ConfigureAwait(false); + + var executedLogEvent = GetLogEvent(ExecutedEndpointLogEventText); + + executedLogEvent.ShouldNotBeNull(); + + executedLogEvent.Properties.ContainsKey(_serilogEnrichersOptions.CorrelationIdPropertyName) + .ShouldNotBeNull(); + + ((ScalarValue) executedLogEvent.Properties[_serilogEnrichersOptions.CorrelationIdPropertyName]).Value + .ShouldBe(result); + } + } +} \ No newline at end of file From c3669cc208512684adceacba8a7ccfa96731fe83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Thu, 9 Jan 2020 10:40:23 +0300 Subject: [PATCH 06/11] Add Volo.Abp.AspNetCore.Serilog to common.ps1 --- nupkg/common.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index eeac13eac8..a582f8c115 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -40,6 +40,7 @@ $projects = ( "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets", + "framework/src/Volo.Abp.AspNetCore.Serilog", "framework/src/Volo.Abp.AspNetCore.TestBase", "framework/src/Volo.Abp.Auditing", "framework/src/Volo.Abp.Authorization", From e84dde4f76abf5ccb45036afce868bde9266e4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Tu=CC=88ken?= Date: Thu, 9 Jan 2020 11:06:50 +0300 Subject: [PATCH 07/11] Change Serilog.Extensions.Hosting package to Serilog.AspNetCore. --- .../Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.csproj | 2 +- .../app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj | 2 +- .../Volo.ClientSimulation.Demo.csproj | 2 +- modules/docs/app/VoloDocs.Web/VoloDocs.Web.csproj | 2 +- .../Acme.BookStore.HttpApi.Host.csproj | 2 +- .../src/Acme.BookStore.Web/Acme.BookStore.Web.csproj | 2 +- .../Acme.BookStore.BookManagement.HttpApi.Host.csproj | 2 +- .../Acme.BookStore.BookManagement.IdentityServer.csproj | 2 +- .../Acme.BookStore.BookManagement.Web.Host.csproj | 2 +- .../Acme.BookStore.BookManagement.Web.Unified.csproj | 2 +- .../BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj | 2 +- .../src/DashboardDemo.Web/DashboardDemo.Web.csproj | 2 +- .../applications/AuthServer.Host/AuthServer.Host.csproj | 2 +- .../BackendAdminApp.Host/BackendAdminApp.Host.csproj | 2 +- .../applications/PublicWebSite.Host/PublicWebSite.Host.csproj | 2 +- .../BackendAdminAppGateway.Host.csproj | 2 +- .../gateways/InternalGateway.Host/InternalGateway.Host.csproj | 2 +- .../PublicWebSiteGateway.Host/PublicWebSiteGateway.Host.csproj | 2 +- .../BloggingService.Host/BloggingService.Host.csproj | 2 +- .../IdentityService.Host/IdentityService.Host.csproj | 2 +- .../ProductService.Host/ProductService.Host.csproj | 2 +- .../MyCompanyName.MyProjectName.HttpApi.Host.csproj | 2 +- .../MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj | 2 +- .../MyCompanyName.MyProjectName.IdentityServer.csproj | 2 +- .../MyCompanyName.MyProjectName.Web.Host.csproj | 2 +- .../MyCompanyName.MyProjectName.Web.csproj | 2 +- .../MyCompanyName.MyProjectName.HttpApi.Host.csproj | 2 +- .../MyCompanyName.MyProjectName.IdentityServer.csproj | 2 +- .../MyCompanyName.MyProjectName.Web.Host.csproj | 2 +- .../MyCompanyName.MyProjectName.Web.Unified.csproj | 2 +- 30 files changed, 30 insertions(+), 30 deletions(-) diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.csproj b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.csproj index 3384fcf332..931eb63088 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.csproj +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.csproj @@ -9,7 +9,7 @@ - + diff --git a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj index 750481d6a1..1ef5fb5c4c 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj +++ b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj @@ -12,7 +12,7 @@ - + diff --git a/modules/client-simulation/demo/Volo.ClientSimulation.Demo/Volo.ClientSimulation.Demo.csproj b/modules/client-simulation/demo/Volo.ClientSimulation.Demo/Volo.ClientSimulation.Demo.csproj index 8544cf6cff..0f9f7bde5e 100644 --- a/modules/client-simulation/demo/Volo.ClientSimulation.Demo/Volo.ClientSimulation.Demo.csproj +++ b/modules/client-simulation/demo/Volo.ClientSimulation.Demo/Volo.ClientSimulation.Demo.csproj @@ -8,7 +8,7 @@ - + diff --git a/modules/docs/app/VoloDocs.Web/VoloDocs.Web.csproj b/modules/docs/app/VoloDocs.Web/VoloDocs.Web.csproj index ef8fc992e3..c5e164247b 100644 --- a/modules/docs/app/VoloDocs.Web/VoloDocs.Web.csproj +++ b/modules/docs/app/VoloDocs.Web/VoloDocs.Web.csproj @@ -14,7 +14,7 @@ - + diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.HttpApi.Host/Acme.BookStore.HttpApi.Host.csproj b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.HttpApi.Host/Acme.BookStore.HttpApi.Host.csproj index 46638e1958..ad0861edc7 100644 --- a/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.HttpApi.Host/Acme.BookStore.HttpApi.Host.csproj +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.HttpApi.Host/Acme.BookStore.HttpApi.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/samples/BookStore-Modular/application/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj b/samples/BookStore-Modular/application/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj index b71bc65d91..9d4115179c 100644 --- a/samples/BookStore-Modular/application/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj +++ b/samples/BookStore-Modular/application/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj @@ -32,7 +32,7 @@ - + diff --git a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.HttpApi.Host/Acme.BookStore.BookManagement.HttpApi.Host.csproj b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.HttpApi.Host/Acme.BookStore.BookManagement.HttpApi.Host.csproj index db35047e19..60f118bc93 100644 --- a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.HttpApi.Host/Acme.BookStore.BookManagement.HttpApi.Host.csproj +++ b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.HttpApi.Host/Acme.BookStore.BookManagement.HttpApi.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.IdentityServer/Acme.BookStore.BookManagement.IdentityServer.csproj b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.IdentityServer/Acme.BookStore.BookManagement.IdentityServer.csproj index c0eebd425a..d9b39f407e 100644 --- a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.IdentityServer/Acme.BookStore.BookManagement.IdentityServer.csproj +++ b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.IdentityServer/Acme.BookStore.BookManagement.IdentityServer.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Host/Acme.BookStore.BookManagement.Web.Host.csproj b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Host/Acme.BookStore.BookManagement.Web.Host.csproj index 0534b56365..1df46016b4 100644 --- a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Host/Acme.BookStore.BookManagement.Web.Host.csproj +++ b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Host/Acme.BookStore.BookManagement.Web.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Unified/Acme.BookStore.BookManagement.Web.Unified.csproj b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Unified/Acme.BookStore.BookManagement.Web.Unified.csproj index 9fb034d5fe..04993f9b69 100644 --- a/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Unified/Acme.BookStore.BookManagement.Web.Unified.csproj +++ b/samples/BookStore-Modular/modules/book-management/host/Acme.BookStore.BookManagement.Web.Unified/Acme.BookStore.BookManagement.Web.Unified.csproj @@ -10,7 +10,7 @@ - + diff --git a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj index 153b6f38e3..832114ce3b 100644 --- a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj +++ b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemo.Web.csproj b/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemo.Web.csproj index 466a7359bc..f00f144407 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemo.Web.csproj +++ b/samples/DashboardDemo/src/DashboardDemo.Web/DashboardDemo.Web.csproj @@ -31,7 +31,7 @@ - + diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj index 337657a831..47bf7813f8 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/applications/BackendAdminApp.Host/BackendAdminApp.Host.csproj b/samples/MicroserviceDemo/applications/BackendAdminApp.Host/BackendAdminApp.Host.csproj index 911593b16a..a22e073228 100644 --- a/samples/MicroserviceDemo/applications/BackendAdminApp.Host/BackendAdminApp.Host.csproj +++ b/samples/MicroserviceDemo/applications/BackendAdminApp.Host/BackendAdminApp.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj index 5574e33b3b..3b4780b2cd 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/PublicWebSite.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj index 9d2d4c3cae..554555940d 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj +++ b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj index 8d7d8bf135..73479d93ad 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGateway.Host.csproj b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGateway.Host.csproj index 2c01555e87..8ece4fe5f4 100644 --- a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGateway.Host.csproj +++ b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGateway.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj b/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj index 5a9c5375d0..cd5bbc8b01 100644 --- a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj +++ b/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj b/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj index 09e91582ab..b9dd199a6c 100644 --- a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj +++ b/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityService.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj index f871ed5983..dc4f6aface 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj @@ -12,7 +12,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj index 173d10bbc2..d41d991542 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj index f59176e5af..9c7f66798e 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj @@ -10,7 +10,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj index e040f9642d..6ff7bde240 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj @@ -32,7 +32,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index ecdd1446fa..0bff1f34fc 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -16,7 +16,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj index 6cf7d25498..db3998cc62 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj @@ -32,7 +32,7 @@ - + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj index 07979b3f63..f041445109 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj index 062dceabaf..2815d81262 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj @@ -8,7 +8,7 @@ - + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index cacefbdb7c..6d6b11231a 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -10,7 +10,7 @@ - + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj index 35fe11e53d..47f8629dde 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/MyCompanyName.MyProjectName.Web.Unified.csproj @@ -10,7 +10,7 @@ - + From f12b488c3fb4bda59225b37e4d2bf2173dbce5b9 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 10 Jan 2020 09:57:57 +0300 Subject: [PATCH 08/11] increase Password max length to 128 --- .../Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs | 7 ++++--- .../Volo/Abp/Identity/IdentityUserConsts.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs index 5abb564b09..40b819e0e1 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Account.Settings; +using Volo.Abp.Identity; using Volo.Abp.Settings; using Volo.Abp.Uow; using IdentityUser = Volo.Abp.Identity.IdentityUser; @@ -55,16 +56,16 @@ namespace Volo.Abp.Account.Web.Pages.Account public class PostInput { [Required] - [StringLength(32)] + [StringLength(IdentityUserConsts.MaxUserNameLength)] public string UserName { get; set; } [Required] [EmailAddress] - [StringLength(255)] + [StringLength(IdentityUserConsts.MaxEmailLength)] public string EmailAddress { get; set; } [Required] - [StringLength(32)] + [StringLength(IdentityUserConsts.MaxPasswordLength)] [DataType(DataType.Password)] public string Password { get; set; } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityUserConsts.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityUserConsts.cs index f56a59e967..ef2cc57ef4 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityUserConsts.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityUserConsts.cs @@ -18,7 +18,7 @@ namespace Volo.Abp.Identity public const int MaxPhoneNumberLength = AbpUserConsts.MaxPhoneNumberLength; - public const int MaxPasswordLength = 32; + public const int MaxPasswordLength = 128; public const int MaxPasswordHashLength = 256; From 52fc8ad3323582ce36338d7c82d358784b6d9a6e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 10 Jan 2020 09:58:39 +0300 Subject: [PATCH 09/11] re-created application template migration --- ...9_Initial.Designer.cs => 20200110065439_Initial.Designer.cs} | 2 +- .../{20200106080719_Initial.cs => 20200110065439_Initial.cs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20200106080719_Initial.Designer.cs => 20200110065439_Initial.Designer.cs} (99%) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20200106080719_Initial.cs => 20200110065439_Initial.cs} (100%) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs similarity index 99% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs index 252d7d8c3d..9a4a1a2023 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs @@ -10,7 +10,7 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.Migrations { [DbContext(typeof(MyProjectNameMigrationsDbContext))] - [Migration("20200106080719_Initial")] + [Migration("20200110065439_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.cs similarity index 100% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.cs From 3715d8c43b27700c7b7d0388555e046724e99aef Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 10 Jan 2020 10:06:44 +0300 Subject: [PATCH 10/11] Revert "re-created application template migration" This reverts commit 52fc8ad3323582ce36338d7c82d358784b6d9a6e. --- ...9_Initial.Designer.cs => 20200106080719_Initial.Designer.cs} | 2 +- .../{20200110065439_Initial.cs => 20200106080719_Initial.cs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20200110065439_Initial.Designer.cs => 20200106080719_Initial.Designer.cs} (99%) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20200110065439_Initial.cs => 20200106080719_Initial.cs} (100%) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs similarity index 99% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs index 9a4a1a2023..252d7d8c3d 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.Designer.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.Designer.cs @@ -10,7 +10,7 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.Migrations { [DbContext(typeof(MyProjectNameMigrationsDbContext))] - [Migration("20200110065439_Initial")] + [Migration("20200106080719_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.cs similarity index 100% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200110065439_Initial.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20200106080719_Initial.cs From 40d0586d49dc6419eac820611b30e9afeec6b569 Mon Sep 17 00:00:00 2001 From: RayMMond Date: Mon, 13 Jan 2020 11:30:08 +0800 Subject: [PATCH 11/11] correct chinese localization --- .../Volo/Abp/Validation/Localization/zh-Hans.json | 4 ++-- .../Volo/Abp/Account/Localization/Resources/zh-Hans.json | 2 +- .../Volo/Abp/Identity/Localization/zh-Hans.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json index ac0c014967..282423a44a 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json @@ -8,7 +8,7 @@ "The {0} field only accepts files with the following extensions: {1}": "{0}字段只允许以下扩展名的文件: {1}", "The field {0} must be a string or array type with a maximum length of '{1}'.": "字段{0}必须是最大长度为'{1}'的字符串或数组.", "The field {0} must be a string or array type with a minimum length of '{1}'.": "字段{0}必须是最小长度为'{1}'的字符串或数组.", - "The {0} field is not a valid phone number.": "字段{0}不是有效的身份证号码.", + "The {0} field is not a valid phone number.": "字段{0}不是有效的手机号码.", "The field {0} must be between {1} and {2}.": "字段{0}值必须在{1}和{2}范围内.", "The field {0} must match the regular expression '{1}'.": "字段{0}必须匹配正则表达式'{1}'.", "The {0} field is required.": "字段{0}不可为空.", @@ -22,7 +22,7 @@ "ThisFieldOnlyAcceptsFilesWithTheFollowingExtensions:{0}": "字段只允许以下扩展名的文件: {0}", "ThisFieldMustBeAStringOrArrayTypeWithAMaximumLengthoOf{0}": "字段必须是最大长度为'{0}'的字符串或数组.", "ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}": "字段必须是最小长度为'{0}'的字符串或数组.", - "ThisFieldIsNotAValidPhoneNumber.": "字段不是有效的身份证号码.", + "ThisFieldIsNotAValidPhoneNumber.": "字段不是有效的手机号码.", "ThisFieldMustBeBetween{0}And{1}": "字段值必须在{0}和{1}范围内.", "ThisFieldMustMatchTheRegularExpression{0}": "字段必须匹配正则表达式'{0}'.", "ThisFieldIsRequired.": "字段不可为空.", diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json index 391dee0531..c778a28dd6 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json @@ -29,7 +29,7 @@ "DisplayName:Surname": "姓", "DisplayName:Password": "密码", "DisplayName:EmailAddress": "电子邮件地址", - "DisplayName:PhoneNumber": "电话号码", + "DisplayName:PhoneNumber": "手机号码", "PersonalSettings": "个人设置", "PersonalSettingsSaved": "个人设置已保存", "PasswordChanged": "修改密码", diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/zh-Hans.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/zh-Hans.json index f57029eb9e..4908f170fa 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/zh-Hans.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/zh-Hans.json @@ -82,7 +82,7 @@ "DisplayName:Abp.Identity.Lockout.LockoutDuration": "锁定时间(秒)", "DisplayName:Abp.Identity.Lockout.MaxFailedAccessAttempts": "最大失败访问尝试次数", "DisplayName:Abp.Identity.SignIn.RequireConfirmedEmail": "要求验证的电子邮箱", - "DisplayName:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "要求验证的电话号码", + "DisplayName:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "要求验证的手机号码", "DisplayName:Abp.Identity.User.IsUserNameUpdateEnabled": "启用用户名更新", "DisplayName:Abp.Identity.User.IsEmailUpdateEnabled": "启用电子邮箱更新", "Description:Abp.Identity.Password.RequiredLength": "密码的最小长度.", @@ -95,7 +95,7 @@ "Description:Abp.Identity.Lockout.LockoutDuration": "当锁定发生时用户被的锁定的时间(秒).", "Description:Abp.Identity.Lockout.MaxFailedAccessAttempts": "如果启用锁定, 当用户被锁定前失败的访问尝试次数.", "Description:Abp.Identity.SignIn.RequireConfirmedEmail": "登录时是否需要验证的电子邮箱.", - "Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "登录时是否需要验证的电话号码.", + "Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "登录时是否需要验证的手机号码.", "Description:Abp.Identity.User.IsUserNameUpdateEnabled": "是否允许用户更新用户名.", "Description:Abp.Identity.User.IsEmailUpdateEnabled": "是否允许用户更新电子邮箱."