Add Serilog and Seq working in Docker
This commit is contained in:
parent
e3daacb9f6
commit
4d6b2f03d2
@ -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.
|
# 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:
|
services:
|
||||||
|
seq:
|
||||||
|
environment:
|
||||||
|
- ACCEPT_EULA=Y
|
||||||
|
ports:
|
||||||
|
- "5340:80"
|
||||||
|
|
||||||
sql.data:
|
sql.data:
|
||||||
environment:
|
environment:
|
||||||
- SA_PASSWORD=Pass@word
|
- SA_PASSWORD=Pass@word
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
version: '3.4'
|
version: '3.4'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
seq:
|
||||||
|
image: datalust/seq:latest
|
||||||
|
|
||||||
sql.data:
|
sql.data:
|
||||||
image: microsoft/mssql-server-linux:2017-latest
|
image: microsoft/mssql-server-linux:2017-latest
|
||||||
|
|
||||||
|
@ -51,7 +51,10 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.1.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.1.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.1.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.1.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
|
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.2" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
|
||||||
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
|
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -9,65 +9,97 @@ using Microsoft.Extensions.Options;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
||||||
{
|
{
|
||||||
public class Program
|
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)
|
var configuration = GetConfiguration();
|
||||||
.MigrateDbContext<CatalogContext>((context,services)=>
|
|
||||||
|
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<CatalogContext>((context, services) =>
|
||||||
{
|
{
|
||||||
var env = services.GetService<IHostingEnvironment>();
|
var env = services.GetService<IHostingEnvironment>();
|
||||||
var settings = services.GetService<IOptions<CatalogSettings>>();
|
var settings = services.GetService<IOptions<CatalogSettings>>();
|
||||||
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
||||||
|
|
||||||
new CatalogContextSeed()
|
new CatalogContextSeed()
|
||||||
.SeedAsync(context,env,settings,logger)
|
.SeedAsync(context, env, settings, logger)
|
||||||
.Wait();
|
.Wait();
|
||||||
|
|
||||||
})
|
})
|
||||||
.MigrateDbContext<IntegrationEventLogContext>((_,__)=> { })
|
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||||
.Run();
|
|
||||||
|
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)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
.UseStartup<Startup>()
|
.CaptureStartupErrors(false)
|
||||||
|
.UseStartup<Startup>()
|
||||||
.UseApplicationInsights()
|
.UseApplicationInsights()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseWebRoot("Pics")
|
.UseWebRoot("Pics")
|
||||||
.ConfigureAppConfiguration((builderContext, config) =>
|
.UseConfiguration(configuration)
|
||||||
{
|
.UseSerilog()
|
||||||
var builtConfig = config.Build();
|
.Build();
|
||||||
|
|
||||||
var configurationBuilder = new ConfigurationBuilder();
|
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
||||||
|
|
||||||
if (Convert.ToBoolean(builtConfig["UseVault"]))
|
return new LoggerConfiguration()
|
||||||
{
|
.MinimumLevel.Verbose()
|
||||||
configurationBuilder.AddAzureKeyVault(
|
.Enrich.WithMachineName()
|
||||||
$"https://{builtConfig["Vault:Name"]}.vault.azure.net/",
|
.Enrich.WithProperty("Application", ApplicationName)
|
||||||
builtConfig["Vault:ClientId"],
|
.Enrich.FromLogContext()
|
||||||
builtConfig["Vault:ClientSecret"]);
|
.WriteTo.Console()
|
||||||
}
|
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
||||||
|
.ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
|
||||||
configurationBuilder.AddEnvironmentVariables();
|
private static IConfiguration GetConfiguration()
|
||||||
|
{
|
||||||
|
var builder = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
config.AddConfiguration(configurationBuilder.Build());
|
var config = builder.Build();
|
||||||
})
|
|
||||||
.ConfigureLogging((hostingContext, builder) =>
|
if (config.GetValue<bool>("UseVault", false))
|
||||||
{
|
{
|
||||||
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
builder.AddAzureKeyVault(
|
||||||
builder.AddConsole();
|
$"https://{config["Vault:Name"]}.vault.azure.net/",
|
||||||
builder.AddDebug();
|
config["Vault:ClientId"],
|
||||||
})
|
config["Vault:ClientSecret"]);
|
||||||
.UseSerilog((builderContext, config) =>
|
}
|
||||||
{
|
|
||||||
config
|
return builder.Build();
|
||||||
.MinimumLevel.Information()
|
}
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console();
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,10 @@
|
|||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "/swagger",
|
"launchUrl": "/swagger",
|
||||||
"environmentVariables": {
|
"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": {
|
"Microsoft.eShopOnContainers.Services.Catalog.API": {
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
"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/",
|
"PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/",
|
||||||
"UseCustomizationData": false,
|
"UseCustomizationData": false,
|
||||||
"Logging": {
|
"Serilog": {
|
||||||
"IncludeScopes": false,
|
"SeqServerUrl": null,
|
||||||
"LogLevel": {
|
"MinimumLevel": {
|
||||||
"Default": "Trace",
|
"Default": "Information",
|
||||||
"System": "Information",
|
"Override": {
|
||||||
"Microsoft": "Information"
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.eShopOnContainers": "Information",
|
||||||
|
"System": "Warning"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AzureServiceBusEnabled": false,
|
"AzureServiceBusEnabled": false,
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<system.webServer>
|
<system.webServer>
|
||||||
<handlers>
|
<handlers>
|
||||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||||
</handlers>
|
</handlers>
|
||||||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false" />
|
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false">
|
||||||
|
<environmentVariables />
|
||||||
|
</aspNetCore>
|
||||||
</system.webServer>
|
</system.webServer>
|
||||||
</configuration>
|
</configuration>
|
Loading…
x
Reference in New Issue
Block a user