|
33 | 33 | using Newtonsoft.Json.Converters;
|
34 | 34 | using OpenIddict.Abstractions;
|
35 | 35 | using OpenIddict.Validation.AspNetCore;
|
| 36 | +using Serilog; |
36 | 37 | using VirtoCommerce.Platform.Core;
|
37 | 38 | using VirtoCommerce.Platform.Core.Common;
|
38 | 39 | using VirtoCommerce.Platform.Core.DynamicProperties;
|
@@ -98,11 +99,26 @@ public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironm
|
98 | 99 | // This method gets called by the runtime. Use this method to add services to the container.
|
99 | 100 | public void ConfigureServices(IServiceCollection services)
|
100 | 101 | {
|
101 |
| - ConsoleLog.BeginOperation("Virto Commerce is loading"); |
| 102 | + // Use temporary bootstrap logger (which will be replaced with configured version later) until DI initialization completed |
| 103 | + Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(Configuration).CreateBootstrapLogger(); |
102 | 104 |
|
103 |
| - var databaseProvider = Configuration.GetValue("DatabaseProvider", "SqlServer"); |
| 105 | + services.AddSerilog((serviceProvider, loggerConfiguration) => |
| 106 | + { |
| 107 | + _ = loggerConfiguration.ReadFrom.Configuration(Configuration); |
| 108 | + |
| 109 | + // Enrich configuration from external sources |
| 110 | + var configurationServices = serviceProvider.GetService<IEnumerable<ILoggerConfigurationService>>(); |
| 111 | + foreach (var service in configurationServices) |
| 112 | + { |
| 113 | + service.Configure(loggerConfiguration); |
| 114 | + } |
| 115 | + // Preserve static logger (i.e. create new logger for DI, instead of reconfiguring existing) |
| 116 | + // to avoid exception about frozen logger because BuildServiceProvider is called multiple times |
| 117 | + }, preserveStaticLogger: true); |
| 118 | + |
| 119 | + Log.ForContext<Startup>().Information("Virto Commerce is loading"); |
104 | 120 |
|
105 |
| - ConsoleLog.EndOperation(); |
| 121 | + var databaseProvider = Configuration.GetValue("DatabaseProvider", "SqlServer"); |
106 | 122 |
|
107 | 123 | // Optional Modules Dependecy Resolving
|
108 | 124 | services.Add(ServiceDescriptor.Singleton(typeof(IOptionalDependency<>), typeof(OptionalDependencyManager<>)));
|
@@ -301,9 +317,8 @@ public void ConfigureServices(IServiceCollection services)
|
301 | 317 | break;
|
302 | 318 | }
|
303 | 319 |
|
304 |
| - ConsoleLog.BeginOperation("Getting server certificate"); |
| 320 | + Log.ForContext<Startup>().Information("Getting server certificate"); |
305 | 321 | ServerCertificate = GetServerCertificate(certificateLoader);
|
306 |
| - ConsoleLog.EndOperation(); |
307 | 322 |
|
308 | 323 | //Create backup of token handler before default claim maps are cleared
|
309 | 324 | // [Obsolete("Use JsonWebToken", DiagnosticId = "VC0009", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")]
|
@@ -671,11 +686,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<
|
671 | 686 | app.UseAutoAccountsLockoutJob(options.Value);
|
672 | 687 |
|
673 | 688 | // Complete modules startup and apply their migrations
|
674 |
| - ConsoleLog.BeginOperation("Post initializing modules"); |
| 689 | + Log.ForContext<Startup>().Information("Post initializing modules"); |
675 | 690 |
|
676 | 691 | app.UseModules();
|
677 |
| - |
678 |
| - ConsoleLog.EndOperation(); |
679 | 692 | });
|
680 | 693 |
|
681 | 694 | app.UseEndpoints(SetupEndpoints);
|
|
0 commit comments