Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Remove serilog (#463)
Krzysztof Pajak4a08d522f235
diff --git a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AppConfig.csindex 19353c2df..799daa72b 100644--- a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs+++ b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs@@ -47,11 +47,5 @@ namespace Grand.Infrastructure.Configuration/// Gets or sets the value to enable a middleware for logging additional information about CurrentCustomer and store/// </summary>public bool EnableContextLoggingMiddleware { get; set; }-- /// <summary>- /// Gets or sets a value indicating - (Serilog) use middleware for smarter HTTP request logging- /// </summary>- public bool UseSerilogRequestLogging { get; set; }-}}diff --git a/src/Core/Grand.Infrastructure/Configuration/ApplicationInsightsConfig.cs b/src/Core/Grand.Infrastructure/Configuration/ApplicationInsightsConfig.csindex 0c0abea16..6d6872d97 100644--- a/src/Core/Grand.Infrastructure/Configuration/ApplicationInsightsConfig.cs+++ b/src/Core/Grand.Infrastructure/Configuration/ApplicationInsightsConfig.cs@@ -3,5 +3,6 @@public class ApplicationInsightsConfig{public bool Enabled { get; set; }+ public string ConnectionString { get; set; }}}diff --git a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csprojindex fbdc60b71..644267fe3 100644--- a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj+++ b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj@@ -17,7 +17,6 @@<PackageReference Include="MediatR" Version="12.2.0" /><PackageReference Include="Scrutor" Version="4.2.2" /><PackageReference Include="StackExchange.Redis" Version="2.7.10" />- <PackageReference Include="Serilog.AspNetCore" Version="8.0.0" /><PackageReference Include="FluentValidation" Version="11.9.0" /></ItemGroup><ItemGroup>diff --git a/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs b/src/Core/Grand.Infrastructure/Plugins/PluginManager.csindex 75aff50fe..245e83cd2 100644--- a/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs+++ b/src/Core/Grand.Infrastructure/Plugins/PluginManager.cs@@ -3,7 +3,7 @@ using Grand.SharedKernel.Extensions;using Microsoft.AspNetCore.Mvc.ApplicationParts;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;-using Serilog;+using Microsoft.Extensions.Logging;using System.Reflection;using System.Runtime.CompilerServices;using System.Runtime.Loader;@@ -29,7 +29,7 @@ namespace Grand.Infrastructure.Pluginsprivate static DirectoryInfo _copyFolder;private static DirectoryInfo _pluginFolder;private static ExtensionsConfig _config;-+ private static ILogger _logger;#endregion#region Methods@@ -54,6 +54,8 @@ namespace Grand.Infrastructure.Pluginsif (mvcCoreBuilder == null)throw new ArgumentNullException(nameof(mvcCoreBuilder));+ _logger = mvcCoreBuilder.Services.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger("PluginManager");+_pluginFolder = new DirectoryInfo(CommonPath.PluginsPath);_copyFolder = new DirectoryInfo(CommonPath.PluginsCopyPath);@@ -63,8 +65,8 @@ namespace Grand.Infrastructure.Pluginsvar installedPluginSystemNames =!string.IsNullOrEmpty(_config.InstalledPlugins) ? _config.InstalledPlugins.Split(",").Select(x=>x.Trim()) :PluginExtensions.ParseInstalledPluginsFile(CommonPath.InstalledPluginsFilePath);-- Log.Information("Creating shadow copy folder and querying for dlls");++ _logger.LogInformation("Creating shadow copy folder and querying for dlls");Directory.CreateDirectory(_pluginFolder.FullName);Directory.CreateDirectory(_copyFolder.FullName);var binFiles = _copyFolder.GetFiles("*", SearchOption.AllDirectories);@@ -73,7 +75,7 @@ namespace Grand.Infrastructure.Plugins//clear out shadow pluginsforeach (var f in binFiles){- Log.Information("Deleting {FName}", f.Name);+ _logger.LogInformation("Deleting {FName}", f.Name);try{var fileName = Path.GetFileName(f.FullName);@@ -84,7 +86,7 @@ namespace Grand.Infrastructure.Plugins}catch (Exception exc){- Log.Error(exc, "PluginManager");+ _logger.LogError(exc, "PluginManager");}}}@@ -94,7 +96,7 @@ namespace Grand.Infrastructure.Plugins{if (plugin.SupportedVersion != GrandVersion.SupportedPluginVersion){- Log.Information("Incompatible plugin {PluginSystemName}", plugin.SystemName);+ _logger.LogInformation("Incompatible plugin {PluginSystemName}", plugin.SystemName);//set as not installedreferencedPlugins.Add(plugin);continue;@@ -124,7 +126,7 @@ namespace Grand.Infrastructure.Plugins}catch (Exception exc){- Log.Error(exc, "PluginManager");+ _logger.LogError(exc, "PluginManager");}}}@@ -279,12 +281,12 @@ namespace Grand.Infrastructure.Pluginsvar areFilesIdentical = shadowCopiedPlug.CreationTimeUtc.Ticks >= plug.CreationTimeUtc.Ticks;if (areFilesIdentical){- Log.Information("Not copying; files appear identical: {Name}", shadowCopiedPlug.Name);+ _logger.LogInformation("Not copying; files appear identical: {Name}", shadowCopiedPlug.Name);return shadowCopiedPlug;}//delete an existing file- Log.Information("New plugin found; Deleting the old file: {Name}", shadowCopiedPlug.Name);+ _logger.LogInformation("New plugin found; Deleting the old file: {Name}", shadowCopiedPlug.Name);try{File.Delete(shadowCopiedPlug.FullName);@@ -292,7 +294,7 @@ namespace Grand.Infrastructure.Pluginscatch (Exception ex){shouldCopy = false;- Log.Error(ex, "PluginManager");+ _logger.LogError(ex, "PluginManager");}}@@ -303,7 +305,7 @@ namespace Grand.Infrastructure.Plugins}catch (IOException){- Log.Information("{FullName} is locked, attempting to rename", shadowCopiedPlug.FullName);+ _logger.LogInformation("{FullName} is locked, attempting to rename", shadowCopiedPlug.FullName);//this occurs when the files are locked,//for some reason devenv locks plugin files some times and for another crazy reason you are allowed to rename them//which releases the lock, so that it what we are doing here, once it's renamed, we can re-shadow copy@@ -334,7 +336,7 @@ namespace Grand.Infrastructure.Pluginstry{//we can now register the plugin definition- Log.Information("Adding to ApplicationParts: '{0}'", systemName);+ _logger.LogInformation("Adding to ApplicationParts: '{0}'", systemName);mvcCoreBuilder.AddApplicationPart(assembly);var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(assembly, throwOnError: false);@@ -349,7 +351,7 @@ namespace Grand.Infrastructure.Plugins}catch (Exception ex){- Log.Error(ex, "PluginManager");+ _logger.LogError(ex, "PluginManager");throw new InvalidOperationException($"The plugin directory for the {systemName} file exists in a folder outside of the allowed grandnode folder hierarchy - exception because of {filename} - exception: {ex.Message}");}}@@ -364,7 +366,7 @@ namespace Grand.Infrastructure.Plugins}catch (Exception ex){- Log.Error(ex, "RegisterPluginInterface");+ _logger.LogError(ex, "RegisterPluginInterface");}}diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.csindex d3f793153..352edc9c2 100644--- a/src/Core/Grand.Infrastructure/StartupBase.cs+++ b/src/Core/Grand.Infrastructure/StartupBase.cs@@ -203,7 +203,7 @@ namespace Grand.Infrastructureservices.AddHttpContextAccessor();//add AppConfig configuration parametersservices.StartupConfig<AppConfig>(configuration.GetSection("Application"));- var performanceConfig = services.StartupConfig<PerformanceConfig>(configuration.GetSection("Performance"));+ services.StartupConfig<PerformanceConfig>(configuration.GetSection("Performance"));services.StartupConfig<SecurityConfig>(configuration.GetSection("Security"));services.StartupConfig<ExtensionsConfig>(configuration.GetSection("Extensions"));services.StartupConfig<CacheConfig>(configuration.GetSection("Cache"));@@ -241,7 +241,7 @@ namespace Grand.Infrastructureoptions.UseJsonBodyModelBinderProviderInsteadOf<ComplexObjectModelBinderProvider>();}});-+return mvcCoreBuilder;}diff --git a/src/Web/Grand.Web.Admin/App_Data/appsettings.json b/src/Web/Grand.Web.Admin/App_Data/appsettings.jsonindex 91fb8dd26..7fcaec52b 100644--- a/src/Web/Grand.Web.Admin/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Admin/App_Data/appsettings.json@@ -23,10 +23,7 @@//Gets or sets the maximum allowed size of any request body in bytes//the default value is 30MB- "MaxRequestBodySize": null, //max 2147483648-- //(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.- "UseSerilogRequestLogging": false+ "MaxRequestBodySize": null //max 2147483648},"Database": {@@ -222,16 +219,6 @@"System": "Information"}},- "Serilog": {- "Using": [ "Serilog.Sinks.Console" ],- "MinimumLevel": "Information",- "Enrich": [ "FromLogContext" ],- "WriteTo": [- {- "Name": "Console"- }- ]- },"ApplicationInsights": {"Enabled": false,"InstrumentationKey": "",diff --git a/src/Web/Grand.Web.Admin/Program.cs b/src/Web/Grand.Web.Admin/Program.csindex 4cd3c4e02..9399dc02a 100644--- a/src/Web/Grand.Web.Admin/Program.cs+++ b/src/Web/Grand.Web.Admin/Program.cs@@ -3,7 +3,6 @@ using Grand.Web.Common.Extensions;using Microsoft.AspNetCore.Builder;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;-using Serilog;Common.WwwRoot = "";@@ -15,11 +14,6 @@ builder.Host.UseDefaultServiceProvider((_, options) =>options.ValidateOnBuild = false;});-//use serilog-builder.Host.UseSerilog((context, services, configuration) => configuration- .ReadFrom.Configuration(context.Configuration)- .Enrich.FromLogContext());-//add configurationbuilder.Configuration.AddAppSettingsJsonFile(args);diff --git a/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs b/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.csindex 6253dcbe0..cdbb16097 100644--- a/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs+++ b/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs@@ -104,7 +104,6 @@ namespace Grand.Web.Common.Infrastructure}catch (Exception ex){- Serilog.Log.Logger.Error(ex, "BackgroundServiceTask");await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);}diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.csindex 9e2a31352..73504efc4 100644--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs@@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Mvc.Razor;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Diagnostics.HealthChecks;+using Microsoft.Extensions.Logging;using Microsoft.Extensions.WebEncoders;using Newtonsoft.Json.Serialization;using StackExchange.Redis;@@ -317,13 +318,27 @@ namespace Grand.Web.Common.Infrastructuretags: new[] { "mongodb" });}- public static void AddApplicationInsights(this IServiceCollection services, IConfiguration configuration)+ public static void AddGrandApplicationInsights(this IServiceCollection services, IConfiguration configuration){var applicationInsights = new ApplicationInsightsConfig();configuration.GetSection("ApplicationInsights").Bind(applicationInsights);if (applicationInsights.Enabled){services.AddApplicationInsightsTelemetry();+ services.AddLogging(builder =>+ {+ builder.AddApplicationInsights(+ configureTelemetryConfiguration: (config) =>+ {+ config.ConnectionString = applicationInsights.ConnectionString;+ },+ configureApplicationInsightsLoggerOptions: (options) =>+ {+ options.IncludeScopes = false;+ options.TrackExceptionsAsExceptionTelemetry = false;+ }+ );+ });}}diff --git a/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.csindex 5f9ebc6a6..283111ccf 100644--- a/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs+++ b/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs@@ -2,7 +2,6 @@using Microsoft.ApplicationInsights.DataContracts;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;-using Serilog.Context;namespace Grand.Web.Common.Middleware;@@ -22,11 +21,6 @@ public class ContextLoggingMiddleware{var workContext = context.RequestServices.GetRequiredService<IWorkContext>();- LogContext.PushProperty(CustomerPropertyName, workContext?.CurrentCustomer?.Email);- LogContext.PushProperty(StorePropertyName, workContext?.CurrentStore?.Name);- LogContext.PushProperty(CurrencyPropertyName, workContext?.WorkingCurrency?.Name);- LogContext.PushProperty(LanguagePropertyName, workContext?.WorkingLanguage?.Name);-var requestTelemetry = context.Features.Get<RequestTelemetry>();if (requestTelemetry != null){diff --git a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.csindex 4c98a37b8..7f1cad91a 100644--- a/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs+++ b/src/Web/Grand.Web.Common/Startup/GrandCommonStartup.cs@@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;-using Serilog;namespace Grand.Web.Common.Startup{@@ -115,12 +114,6 @@ namespace Grand.Web.Common.Startupif (!performanceConfig.IgnoreUsePoweredByMiddleware)application.UsePoweredBy();- // Write streamlined request completion events, instead of the more verbose ones from the framework.- // To use the default framework request logging instead, remove this line and set the "Microsoft"- // level in app settings json to "Information".- if (appConfig.UseSerilogRequestLogging)- application.UseSerilogRequestLogging();-//add responsive middleware (for detection)application.UseGrandDetection();diff --git a/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs b/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.csindex 2a556b733..48b819fd1 100644--- a/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs+++ b/src/Web/Grand.Web.Common/Startup/GrandMvcStartup.cs@@ -26,7 +26,7 @@ namespace Grand.Web.Common.Startupservices.AddGrandMiniProfiler();//add ApplicationInsights- services.AddApplicationInsights(configuration);+ services.AddGrandApplicationInsights(configuration);//add and configure MVC featureservices.AddGrandMvc(configuration);diff --git a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json b/src/Web/Grand.Web.Vendor/App_Data/appsettings.jsonindex 91fb8dd26..7fcaec52b 100644--- a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Vendor/App_Data/appsettings.json@@ -23,10 +23,7 @@//Gets or sets the maximum allowed size of any request body in bytes//the default value is 30MB- "MaxRequestBodySize": null, //max 2147483648-- //(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.- "UseSerilogRequestLogging": false+ "MaxRequestBodySize": null //max 2147483648},"Database": {@@ -222,16 +219,6 @@"System": "Information"}},- "Serilog": {- "Using": [ "Serilog.Sinks.Console" ],- "MinimumLevel": "Information",- "Enrich": [ "FromLogContext" ],- "WriteTo": [- {- "Name": "Console"- }- ]- },"ApplicationInsights": {"Enabled": false,"InstrumentationKey": "",diff --git a/src/Web/Grand.Web.Vendor/Program.cs b/src/Web/Grand.Web.Vendor/Program.csindex c6d966295..8c9fc5ed4 100644--- a/src/Web/Grand.Web.Vendor/Program.cs+++ b/src/Web/Grand.Web.Vendor/Program.cs@@ -3,7 +3,6 @@ using Grand.Web.Vendor.Extensions;using Microsoft.AspNetCore.Builder;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;-using Serilog;Constants.WwwRoot = "";@@ -15,11 +14,6 @@ builder.Host.UseDefaultServiceProvider((_, options) =>options.ValidateOnBuild = false;});-//use serilog-builder.Host.UseSerilog((context, services, configuration) => configuration- .ReadFrom.Configuration(context.Configuration)- .Enrich.FromLogContext());-//add configurationbuilder.Configuration.AddAppSettingsJsonFile(args);diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.jsonindex 1874bf8e5..c8031fa08 100644--- a/src/Web/Grand.Web/App_Data/appsettings.json+++ b/src/Web/Grand.Web/App_Data/appsettings.json@@ -30,10 +30,7 @@"MaxRequestBodySize": null, //max 2147483648//Gets or sets the value to enable a middleware for logging additional information about CurrentCustomer and CurrentStore- "EnableContextLoggingMiddleware": false,-- //(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.- "UseSerilogRequestLogging": false+ "EnableContextLoggingMiddleware": true},"Database": {@@ -255,19 +252,8 @@"System": "Information"}},- "Serilog": {- "Using": [ "Serilog.Sinks.Console" ],- "MinimumLevel": "Information",- "Enrich": [ "FromLogContext" ],- "WriteTo": [- {- "Name": "Console"- }- ]- },"ApplicationInsights": {"Enabled": false,- "InstrumentationKey": "",- "EnableAdaptiveSampling": false+ "ConnectionString": ""}}diff --git a/src/Web/Grand.Web/Program.cs b/src/Web/Grand.Web/Program.csindex 9bc56f009..f7f9eedf6 100644--- a/src/Web/Grand.Web/Program.cs+++ b/src/Web/Grand.Web/Program.cs@@ -1,9 +1,7 @@using Grand.Web.Common.Extensions;using Grand.Web.Common.Startup;using Microsoft.AspNetCore.Builder;-using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;-using Serilog;using StartupBase = Grand.Infrastructure.StartupBase;var builder = WebApplication.CreateBuilder(args);@@ -14,13 +12,6 @@ builder.Host.UseDefaultServiceProvider((_, options) =>options.ValidateOnBuild = false;});-builder.Services.AddLogging();--//use serilog-builder.Host.UseSerilog((context, _, configuration) => configuration- .ReadFrom.Configuration(context.Configuration)- .Enrich.FromLogContext());-//add configurationbuilder.Configuration.AddAppSettingsJsonFile(args);