diff --git a/docker-compose.override.yml b/docker-compose.override.yml
index a0a3b35b7..4c9ab72a8 100644
--- a/docker-compose.override.yml
+++ b/docker-compose.override.yml
@@ -7,6 +7,12 @@ version: '3.4'
# An external IP or DNS name has to be used (instead localhost and the 10.0.75.1 IP) when testing the Web apps and the Xamarin apps from remote machines/devices using the same WiFi, for instance.
services:
+ seq:
+ environment:
+ - ACCEPT_EULA=Y
+ ports:
+ - "5340:80"
+
sql.data:
environment:
- SA_PASSWORD=Pass@word
diff --git a/docker-compose.yml b/docker-compose.yml
index 95610ebd5..04f961816 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,6 +1,9 @@
version: '3.4'
services:
+ seq:
+ image: datalust/seq:latest
+
sql.data:
image: microsoft/mssql-server-linux:2017-latest
diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj
index a2be6b522..962f03ade 100644
--- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj
+++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj
@@ -51,7 +51,10 @@
+
+
+
diff --git a/src/Services/Catalog/Catalog.API/Program.cs b/src/Services/Catalog/Catalog.API/Program.cs
index 3f4c19955..82e0041a0 100644
--- a/src/Services/Catalog/Catalog.API/Program.cs
+++ b/src/Services/Catalog/Catalog.API/Program.cs
@@ -9,65 +9,97 @@ using Microsoft.Extensions.Options;
using Serilog;
using System;
using System.IO;
+
namespace Microsoft.eShopOnContainers.Services.Catalog.API
{
public class Program
{
- public static void Main(string[] args)
+ private static readonly string ApplicationName = typeof(Program).Namespace;
+
+ public static int Main(string[] args)
{
- BuildWebHost(args)
- .MigrateDbContext((context,services)=>
+ var configuration = GetConfiguration();
+
+ Log.Logger = CreateSerilogLogger(configuration);
+
+ try
+ {
+ Log.Information("Configuring web host ({Application})...", ApplicationName);
+ var host = BuildWebHost(configuration, args);
+
+ Log.Information("Applying migrations ({Application})...", ApplicationName);
+ host.MigrateDbContext((context, services) =>
{
var env = services.GetService();
var settings = services.GetService>();
var logger = services.GetService>();
new CatalogContextSeed()
- .SeedAsync(context,env,settings,logger)
+ .SeedAsync(context, env, settings, logger)
.Wait();
-
})
- .MigrateDbContext((_,__)=> { })
- .Run();
+ .MigrateDbContext((_, __) => { });
+
+ Log.Information("Starting web host ({Application})...", ApplicationName);
+ host.Run();
+
+ return 0;
+ }
+ catch (Exception ex)
+ {
+ Log.Fatal(ex, "Program terminated unexpectedly ({Application})!", ApplicationName);
+ return 1;
+ }
+ finally
+ {
+ Log.CloseAndFlush();
+ }
}
- public static IWebHost BuildWebHost(string[] args) =>
+ private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) =>
WebHost.CreateDefaultBuilder(args)
- .UseStartup()
+ .CaptureStartupErrors(false)
+ .UseStartup()
.UseApplicationInsights()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseWebRoot("Pics")
- .ConfigureAppConfiguration((builderContext, config) =>
- {
- var builtConfig = config.Build();
+ .UseConfiguration(configuration)
+ .UseSerilog()
+ .Build();
+
+ private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
+ {
+ var seqServerUrl = configuration["Serilog:SeqServerUrl"];
- var configurationBuilder = new ConfigurationBuilder();
+ return new LoggerConfiguration()
+ .MinimumLevel.Verbose()
+ .Enrich.WithMachineName()
+ .Enrich.WithProperty("Application", ApplicationName)
+ .Enrich.FromLogContext()
+ .WriteTo.Console()
+ .WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
+ .ReadFrom.Configuration(configuration)
+ .CreateLogger();
+ }
- if (Convert.ToBoolean(builtConfig["UseVault"]))
- {
- configurationBuilder.AddAzureKeyVault(
- $"https://{builtConfig["Vault:Name"]}.vault.azure.net/",
- builtConfig["Vault:ClientId"],
- builtConfig["Vault:ClientSecret"]);
- }
+ private static IConfiguration GetConfiguration()
+ {
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
+ .AddEnvironmentVariables();
- configurationBuilder.AddEnvironmentVariables();
+ var config = builder.Build();
- config.AddConfiguration(configurationBuilder.Build());
- })
- .ConfigureLogging((hostingContext, builder) =>
- {
- builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
- builder.AddConsole();
- builder.AddDebug();
- })
- .UseSerilog((builderContext, config) =>
- {
- config
- .MinimumLevel.Information()
- .Enrich.FromLogContext()
- .WriteTo.Console();
- })
- .Build();
+ if (config.GetValue("UseVault", false))
+ {
+ builder.AddAzureKeyVault(
+ $"https://{config["Vault:Name"]}.vault.azure.net/",
+ config["Vault:ClientId"],
+ config["Vault:ClientSecret"]);
+ }
+
+ return builder.Build();
+ }
}
}
\ No newline at end of file
diff --git a/src/Services/Catalog/Catalog.API/Properties/launchSettings.json b/src/Services/Catalog/Catalog.API/Properties/launchSettings.json
index 2b21ca280..8f2cde4db 100644
--- a/src/Services/Catalog/Catalog.API/Properties/launchSettings.json
+++ b/src/Services/Catalog/Catalog.API/Properties/launchSettings.json
@@ -13,7 +13,10 @@
"launchBrowser": true,
"launchUrl": "/swagger",
"environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
+ "ConnectionString": "server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "EventBusConnection": "localhost",
+ "Serilog:SeqServerUrl": "http://locahost:5340"
}
},
"Microsoft.eShopOnContainers.Services.Catalog.API": {
diff --git a/src/Services/Catalog/Catalog.API/appsettings.json b/src/Services/Catalog/Catalog.API/appsettings.json
index 0bf489699..b26f63bff 100644
--- a/src/Services/Catalog/Catalog.API/appsettings.json
+++ b/src/Services/Catalog/Catalog.API/appsettings.json
@@ -2,12 +2,15 @@
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
"PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/",
"UseCustomizationData": false,
- "Logging": {
- "IncludeScopes": false,
- "LogLevel": {
- "Default": "Trace",
- "System": "Information",
- "Microsoft": "Information"
+ "Serilog": {
+ "SeqServerUrl": null,
+ "MinimumLevel": {
+ "Default": "Information",
+ "Override": {
+ "Microsoft": "Warning",
+ "Microsoft.eShopOnContainers": "Information",
+ "System": "Warning"
+ }
}
},
"AzureServiceBusEnabled": false,
diff --git a/src/Services/Catalog/Catalog.API/web.config b/src/Services/Catalog/Catalog.API/web.config
index e04a0397b..2157aef31 100644
--- a/src/Services/Catalog/Catalog.API/web.config
+++ b/src/Services/Catalog/Catalog.API/web.config
@@ -2,8 +2,10 @@
-
+
-
+
+
+
\ No newline at end of file