Remove Serilog usage
This commit is contained in:
parent
5342c86af0
commit
8da0a81514
@ -25,7 +25,6 @@ global using Microsoft.Extensions.Hosting;
|
|||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Microsoft.OpenApi.Models;
|
global using Microsoft.OpenApi.Models;
|
||||||
global using Serilog;
|
|
||||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
global using System.IdentityModel.Tokens.Jwt;
|
global using System.IdentityModel.Tokens.Jwt;
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
await BuildWebHost(args).RunAsync();
|
await BuildWebHost(args).RunAsync();
|
||||||
IWebHost BuildWebHost(string[] args) =>
|
IWebHost BuildWebHost(string[] args) =>
|
||||||
WebHost
|
WebHost
|
||||||
.CreateDefaultBuilder(args)
|
.CreateDefaultBuilder(args)
|
||||||
@ -13,11 +13,4 @@ IWebHost BuildWebHost(string[] args) =>
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.UseSerilog((builderContext, config) =>
|
.Build();
|
||||||
{
|
|
||||||
config
|
|
||||||
.MinimumLevel.Information()
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console();
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
@ -12,9 +12,10 @@ namespace EventBus.Tests
|
|||||||
Handled = false;
|
Handled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(TestIntegrationEvent @event)
|
public Task Handle(TestIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
Handled = true;
|
Handled = true;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,10 @@ namespace EventBus.Tests
|
|||||||
Handled = false;
|
Handled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(TestIntegrationEvent @event)
|
public Task Handle(TestIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
Handled = true;
|
Handled = true;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,6 @@
|
|||||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
|
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
|
||||||
<PackageVersion Include="Polly" Version="7.2.3" />
|
<PackageVersion Include="Polly" Version="7.2.3" />
|
||||||
<PackageVersion Include="RabbitMQ.Client" Version="6.4.0" />
|
<PackageVersion Include="RabbitMQ.Client" Version="6.4.0" />
|
||||||
<PackageVersion Include="Serilog.AspNetCore" Version="6.1.0" />
|
|
||||||
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.2.1-dev-00787" />
|
|
||||||
<PackageVersion Include="Serilog.Settings.Configuration" Version="3.5.0-dev-00359" />
|
|
||||||
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.1-dev-00896" />
|
|
||||||
<PackageVersion Include="Serilog.Sinks.Http" Version="8.0.0" />
|
|
||||||
<PackageVersion Include="Serilog.Sinks.Seq" Version="5.2.3-dev-00260" />
|
|
||||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
<PackageVersion Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
|
<PackageVersion Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
|
||||||
<PackageVersion Include="System.Data.SqlClient" Version="4.8.5" />
|
<PackageVersion Include="System.Data.SqlClient" Version="4.8.5" />
|
||||||
|
@ -33,6 +33,5 @@ global using Microsoft.Extensions.Configuration;
|
|||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Hosting;
|
global using Microsoft.Extensions.Hosting;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Serilog.Context;
|
|
||||||
global using Services.Common;
|
global using Services.Common;
|
||||||
global using StackExchange.Redis;
|
global using StackExchange.Redis;
|
||||||
|
@ -15,7 +15,7 @@ public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<Orde
|
|||||||
|
|
||||||
public async Task Handle(OrderStartedIntegrationEvent @event)
|
public async Task Handle(OrderStartedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}"))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandl
|
|||||||
|
|
||||||
public async Task Handle(ProductPriceChangedIntegrationEvent @event)
|
public async Task Handle(ProductPriceChangedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}"))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Debug",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Debug",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IdentityUrlExternal": "http://localhost:5105",
|
"IdentityUrlExternal": "http://localhost:5105",
|
||||||
"IdentityUrl": "http://localhost:5105",
|
"IdentityUrl": "http://localhost:5105",
|
||||||
"ConnectionString": "127.0.0.1",
|
"ConnectionString": "127.0.0.1",
|
||||||
|
@ -60,12 +60,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
|
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
||||||
<PackageReference Include="System.Data.SqlClient" />
|
<PackageReference Include="System.Data.SqlClient" />
|
||||||
|
@ -44,4 +44,3 @@ global using Microsoft.Extensions.Logging;
|
|||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Polly;
|
global using Polly;
|
||||||
global using Polly.Retry;
|
global using Polly.Retry;
|
||||||
global using Serilog.Context;
|
|
||||||
|
@ -19,7 +19,7 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public class OrderStatusChangedToPaidIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
|
@ -14,10 +14,8 @@
|
|||||||
"launchUrl": "/swagger",
|
"launchUrl": "/swagger",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ConnectionString": "server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
"ConnectionString": "server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
||||||
"Serilog:LogstashgUrl": "http://locahost:8080",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"EventBusConnection": "localhost",
|
"EventBusConnection": "localhost"
|
||||||
"Serilog:SeqServerUrl": "http://locahost:5340"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Microsoft.eShopOnContainers.Services.Catalog.API": {
|
"Microsoft.eShopOnContainers.Services.Catalog.API": {
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
{
|
{
|
||||||
"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/",
|
||||||
"Serilog": {
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Debug",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Debug",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"EventBusConnection": "localhost"
|
"EventBusConnection": "localhost"
|
||||||
}
|
}
|
@ -1,17 +1,5 @@
|
|||||||
{
|
{
|
||||||
"UseCustomizationData": false,
|
"UseCustomizationData": false,
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AzureServiceBusEnabled": false,
|
"AzureServiceBusEnabled": false,
|
||||||
"AzureStorageEnabled": false,
|
"AzureStorageEnabled": false,
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
|
@ -8,10 +8,8 @@
|
|||||||
<environmentVariables>
|
<environmentVariables>
|
||||||
<environmentVariable name="COMPLUS_ForceENC" value="1" />
|
<environmentVariable name="COMPLUS_ForceENC" value="1" />
|
||||||
<environmentVariable name="ConnectionString" value="server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true" />
|
<environmentVariable name="ConnectionString" value="server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true" />
|
||||||
<environmentVariable name="Serilog:LogstashgUrl" value="http://locahost:8080" />
|
|
||||||
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||||
<environmentVariable name="EventBusConnection" value="localhost" />
|
<environmentVariable name="EventBusConnection" value="localhost" />
|
||||||
<environmentVariable name="Serilog:SeqServerUrl" value="http://locahost:5340" />
|
|
||||||
</environmentVariables>
|
</environmentVariables>
|
||||||
</aspNetCore>
|
</aspNetCore>
|
||||||
</system.webServer>
|
</system.webServer>
|
||||||
|
@ -4,17 +4,6 @@
|
|||||||
"SpaClient": "http://localhost:5104",
|
"SpaClient": "http://localhost:5104",
|
||||||
"XamarinCallback": "http://localhost:5105/xamarincallback",
|
"XamarinCallback": "http://localhost:5105/xamarincallback",
|
||||||
"UseCustomizationData": false,
|
"UseCustomizationData": false,
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft.AspNetCore": "Warning",
|
|
||||||
"Microsoft.EntityFramework": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"InstrumentationKey": ""
|
"InstrumentationKey": ""
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TReque
|
|||||||
Guid transactionId;
|
Guid transactionId;
|
||||||
|
|
||||||
await using var transaction = await _dbContext.BeginTransactionAsync();
|
await using var transaction = await _dbContext.BeginTransactionAsync();
|
||||||
using (LogContext.PushProperty("TransactionContext", transaction.TransactionId))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("TransactionContext", transaction.TransactionId) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Begin transaction {TransactionId} for {CommandName} ({@Command})", transaction.TransactionId, typeName, request);
|
_logger.LogInformation("----- Begin transaction {TransactionId} for {CommandName} ({@Command})", transaction.TransactionId, typeName, request);
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ public class GracePeriodConfirmedIntegrationEventHandler : IIntegrationEventHand
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Handle(GracePeriodConfirmedIntegrationEvent @event)
|
public async Task Handle(GracePeriodConfirmedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
|
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ public class OrderPaymentFailedIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
|
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var command = new CancelOrderCommand(@event.OrderId);
|
var command = new CancelOrderCommand(@event.OrderId);
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ public class OrderPaymentSucceededIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderPaymentSucceededIntegrationEvent @event)
|
public async Task Handle(OrderPaymentSucceededIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var command = new SetPaidOrderStatusCommand(@event.OrderId);
|
var command = new SetPaidOrderStatusCommand(@event.OrderId);
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ public class OrderStockConfirmedIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
|
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
|
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@ public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandle
|
|||||||
|
|
||||||
public async Task Handle(OrderStockRejectedIntegrationEvent @event)
|
public async Task Handle(OrderStockRejectedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var orderStockRejectedItems = @event.OrderStockItems
|
var orderStockRejectedItems = @event.OrderStockItems
|
||||||
.FindAll(c => !c.HasStock)
|
.FindAll(c => !c.HasStock)
|
||||||
|
@ -24,15 +24,15 @@ public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHand
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event)
|
public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
var result = false;
|
var result = false;
|
||||||
|
|
||||||
if (@event.RequestId != Guid.Empty)
|
if (@event.RequestId != Guid.Empty)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IdentifiedCommandId", @event.RequestId))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IdentifiedCommandId", @event.RequestId) }))
|
||||||
{
|
{
|
||||||
var createOrderCommand = new CreateOrderCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.City, @event.Street,
|
var createOrderCommand = new CreateOrderCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.City, @event.Street,
|
||||||
@event.State, @event.Country, @event.ZipCode,
|
@event.State, @event.Country, @event.ZipCode,
|
||||||
|
@ -27,7 +27,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
|
|||||||
|
|
||||||
foreach (var logEvt in pendingLogEvents)
|
foreach (var logEvt in pendingLogEvents)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", logEvt.EventId, Program.AppName, logEvt.IntegrationEvent);
|
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", logEvt.EventId, logEvt.IntegrationEvent);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId} from {AppName}", logEvt.EventId, Program.AppName);
|
_logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId}", logEvt.EventId);
|
||||||
|
|
||||||
await _eventLogService.MarkEventAsFailedAsync(logEvt.EventId);
|
await _eventLogService.MarkEventAsFailedAsync(logEvt.EventId);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
|
||||||
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
|
|
||||||
|
|
||||||
public static class BasketItemExtensions
|
public static class BasketItemExtensions
|
||||||
{
|
{
|
||||||
|
@ -64,8 +64,6 @@ global using Microsoft.OpenApi.Models;
|
|||||||
global using Polly.Retry;
|
global using Polly.Retry;
|
||||||
global using Polly;
|
global using Polly;
|
||||||
global using RabbitMQ.Client;
|
global using RabbitMQ.Client;
|
||||||
global using Serilog.Context;
|
|
||||||
global using Serilog;
|
|
||||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
global using System.Data.Common;
|
global using System.Data.Common;
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="Ordering.FunctionalTests"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Protobuf Include="Proto\ordering.proto" GrpcServices="Server" Generator="MSBuild:Compile" />
|
<Protobuf Include="Proto\ordering.proto" GrpcServices="Server" Generator="MSBuild:Compile" />
|
||||||
@ -60,12 +63,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.NETCore.Platforms" />
|
<PackageReference Include="Microsoft.NETCore.Platforms" />
|
||||||
<PackageReference Include="Polly" />
|
<PackageReference Include="Polly" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -24,14 +24,10 @@ builder.WebHost.ConfigureKestrel(options =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
builder.Services.AddGrpc(options => options.EnableDetailedErrors = true);
|
||||||
|
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
||||||
|
builder.Services.AddApplicationInsightsKubernetesEnricher();
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddGrpc(options =>
|
|
||||||
{
|
|
||||||
options.EnableDetailedErrors = true;
|
|
||||||
})
|
|
||||||
.Services
|
|
||||||
.AddApplicationInsights(builder.Configuration)
|
|
||||||
.AddCustomMvc()
|
.AddCustomMvc()
|
||||||
.AddHealthChecks(builder.Configuration)
|
.AddHealthChecks(builder.Configuration)
|
||||||
.AddCustomDbContext(builder.Configuration)
|
.AddCustomDbContext(builder.Configuration)
|
||||||
@ -58,41 +54,6 @@ var services = builder.Services;
|
|||||||
cfg.AddOpenBehavior(typeof(TransactionBehavior<,>));
|
cfg.AddOpenBehavior(typeof(TransactionBehavior<,>));
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
// Register all the command handlers.
|
|
||||||
services.AddSingleton<IRequestHandler<CancelOrderCommand, bool>, CancelOrderCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<CancelOrderCommand, bool>, bool>, CancelOrderIdentifiedCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<CreateOrderCommand, bool>, CreateOrderCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<CreateOrderCommand, bool>, bool>, CreateOrderIdentifiedCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<CreateOrderDraftCommand, OrderDraftDTO>, CreateOrderDraftCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<SetAwaitingValidationOrderStatusCommand, bool>, bool>, SetAwaitingValidationIdentifiedOrderStatusCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<SetAwaitingValidationOrderStatusCommand, bool>, SetAwaitingValidationOrderStatusCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<SetPaidOrderStatusCommand, bool>, bool>, SetPaidIdentifiedOrderStatusCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<SetPaidOrderStatusCommand, bool>, SetPaidOrderStatusCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<SetStockConfirmedOrderStatusCommand, bool>, bool>, SetStockConfirmedOrderStatusIdentifiedCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<SetStockConfirmedOrderStatusCommand, bool>, SetStockConfirmedOrderStatusCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<SetStockRejectedOrderStatusCommand, bool>, bool>, SetStockRejectedOrderStatusIdentifiedCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<SetStockRejectedOrderStatusCommand, bool>, SetStockRejectedOrderStatusCommandHandler>();
|
|
||||||
|
|
||||||
services.AddSingleton<IRequestHandler<IdentifiedCommand<ShipOrderCommand, bool>, bool>, ShipOrderIdentifiedCommandHandler>();
|
|
||||||
services.AddSingleton<IRequestHandler<ShipOrderCommand, bool>, ShipOrderCommandHandler>();
|
|
||||||
|
|
||||||
// Register the DomainEventHandler classes (they implement INotificationHandler<>) in assembly holding the Domain Events
|
|
||||||
services.AddSingleton<INotificationHandler<OrderCancelledDomainEvent>, OrderCancelledDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<OrderShippedDomainEvent>, OrderShippedDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<OrderStatusChangedToAwaitingValidationDomainEvent>, OrderStatusChangedToAwaitingValidationDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<OrderStatusChangedToPaidDomainEvent>, OrderStatusChangedToPaidDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<OrderStatusChangedToStockConfirmedDomainEvent>, OrderStatusChangedToStockConfirmedDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent>, UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler>();
|
|
||||||
services.AddSingleton<INotificationHandler<OrderStartedDomainEvent>, ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler>();
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Register the command validators for the validator behavior (validators based on FluentValidation library)
|
// Register the command validators for the validator behavior (validators based on FluentValidation library)
|
||||||
services.AddSingleton<IValidator<CancelOrderCommand>, CancelOrderCommandValidator>();
|
services.AddSingleton<IValidator<CancelOrderCommand>, CancelOrderCommandValidator>();
|
||||||
services.AddSingleton<IValidator<CreateOrderCommand>, CreateOrderCommandValidator>();
|
services.AddSingleton<IValidator<CreateOrderCommand>, CreateOrderCommandValidator>();
|
||||||
@ -135,13 +96,12 @@ if (!string.IsNullOrEmpty(pathBase))
|
|||||||
{
|
{
|
||||||
app.UsePathBase(pathBase);
|
app.UsePathBase(pathBase);
|
||||||
}
|
}
|
||||||
app.UseSwagger()
|
app.UseSwagger().UseSwaggerUI(c =>
|
||||||
.UseSwaggerUI(c =>
|
{
|
||||||
{
|
c.SwaggerEndpoint($"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json", "Ordering.API V1");
|
||||||
c.SwaggerEndpoint($"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json", "Ordering.API V1");
|
c.OAuthClientId("orderingswaggerui");
|
||||||
c.OAuthClientId("orderingswaggerui");
|
c.OAuthAppName("Ordering Swagger UI");
|
||||||
c.OAuthAppName("Ordering Swagger UI");
|
});
|
||||||
});
|
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy");
|
||||||
@ -174,10 +134,9 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
|||||||
Predicate = r => r.Name.Contains("self")
|
Predicate = r => r.Name.Contains("self")
|
||||||
});
|
});
|
||||||
ConfigureEventBus(app);
|
ConfigureEventBus(app);
|
||||||
try
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
Log.Information("Applying migrations ({ApplicationContext})...", Program.AppName);
|
|
||||||
using var scope = app.Services.CreateScope();
|
|
||||||
var context = scope.ServiceProvider.GetRequiredService<OrderingContext>();
|
var context = scope.ServiceProvider.GetRequiredService<OrderingContext>();
|
||||||
var env = app.Services.GetService<IWebHostEnvironment>();
|
var env = app.Services.GetService<IWebHostEnvironment>();
|
||||||
var settings = app.Services.GetService<IOptions<OrderingSettings>>();
|
var settings = app.Services.GetService<IOptions<OrderingSettings>>();
|
||||||
@ -187,21 +146,10 @@ try
|
|||||||
await new OrderingContextSeed().SeedAsync(context, env, settings, logger);
|
await new OrderingContextSeed().SeedAsync(context, env, settings, logger);
|
||||||
var integEventContext = scope.ServiceProvider.GetRequiredService<IntegrationEventLogContext>();
|
var integEventContext = scope.ServiceProvider.GetRequiredService<IntegrationEventLogContext>();
|
||||||
await integEventContext.Database.MigrateAsync();
|
await integEventContext.Database.MigrateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName);
|
await app.RunAsync();
|
||||||
await app.RunAsync();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
void ConfigureEventBus(IApplicationBuilder app)
|
void ConfigureEventBus(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||||
@ -213,37 +161,9 @@ void ConfigureEventBus(IApplicationBuilder app)
|
|||||||
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
||||||
eventBus.Subscribe<OrderPaymentSucceededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSucceededIntegrationEvent>>();
|
eventBus.Subscribe<OrderPaymentSucceededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSucceededIntegrationEvent>>();
|
||||||
}
|
}
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
return new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class Program
|
|
||||||
{
|
|
||||||
private static string Namespace = typeof(Program).Assembly.GetName().Name;
|
|
||||||
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CustomExtensionsMethods
|
static class CustomExtensionsMethods
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration)
|
|
||||||
{
|
|
||||||
services.AddApplicationInsightsTelemetry(configuration);
|
|
||||||
services.AddApplicationInsightsKubernetesEnricher();
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddCustomMvc(this IServiceCollection services)
|
public static IServiceCollection AddCustomMvc(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
|
@ -2,18 +2,6 @@
|
|||||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true",
|
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true",
|
||||||
"IdentityUrl": "http://localhost:5105",
|
"IdentityUrl": "http://localhost:5105",
|
||||||
"UseCustomizationData": false,
|
"UseCustomizationData": false,
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AzureServiceBusEnabled": false,
|
"AzureServiceBusEnabled": false,
|
||||||
"SubscriptionClientName": "Ordering",
|
"SubscriptionClientName": "Ordering",
|
||||||
"GracePeriodTime": "1",
|
"GracePeriodTime": "1",
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
using Autofac;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Ordering.BackgroundTasks.Extensions
|
namespace Ordering.BackgroundTasks.Extensions
|
||||||
{
|
{
|
||||||
@ -120,23 +115,5 @@ namespace Ordering.BackgroundTasks.Extensions
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ILoggingBuilder UseSerilog(this ILoggingBuilder builder, IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
global using Autofac.Extensions.DependencyInjection;
|
global using Microsoft.AspNetCore.Hosting;
|
||||||
global using Microsoft.AspNetCore.Hosting;
|
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.Hosting;
|
global using Microsoft.Extensions.Hosting;
|
||||||
global using Ordering.BackgroundTasks.Extensions;
|
global using Ordering.BackgroundTasks.Extensions;
|
||||||
global using Serilog;
|
|
||||||
global using System.IO;
|
global using System.IO;
|
||||||
global using HealthChecks.UI.Client;
|
global using HealthChecks.UI.Client;
|
||||||
global using Microsoft.AspNetCore.Builder;
|
global using Microsoft.AspNetCore.Builder;
|
||||||
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
global using Microsoft.Extensions.Configuration;
|
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Ordering.BackgroundTasks.Extensions;
|
|
||||||
global using Ordering.BackgroundTasks.Services;
|
global using Ordering.BackgroundTasks.Services;
|
||||||
global using System;
|
global using System;
|
||||||
global using Ordering.BackgroundTasks;
|
global using Ordering.BackgroundTasks;
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
<PackageReference Include="System.Data.SqlClient" />
|
<PackageReference Include="System.Data.SqlClient" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
var appName = "Ordering.BackgroundTasks";
|
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
|
||||||
{
|
{
|
||||||
Args = args,
|
Args = args,
|
||||||
ApplicationName = typeof(Program).Assembly.FullName
|
ApplicationName = typeof(Program).Assembly.FullName
|
||||||
@ -8,7 +7,6 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory());
|
|||||||
builder.Configuration.AddJsonFile("appsettings.json", optional: true);
|
builder.Configuration.AddJsonFile("appsettings.json", optional: true);
|
||||||
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true);
|
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true);
|
||||||
builder.Configuration.AddEnvironmentVariables();
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
|
||||||
builder.Services.AddCustomHealthCheck(builder.Configuration)
|
builder.Services.AddCustomHealthCheck(builder.Configuration)
|
||||||
.Configure<BackgroundTaskSettings>(builder.Configuration)
|
.Configure<BackgroundTaskSettings>(builder.Configuration)
|
||||||
.AddOptions()
|
.AddOptions()
|
||||||
@ -35,37 +33,7 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
|||||||
Predicate = r => r.Name.Contains("self")
|
Predicate = r => r.Name.Contains("self")
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
await app.RunAsync();
|
||||||
{
|
|
||||||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName);
|
|
||||||
await app.RunAsync();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
|
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
return new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
|
@ -36,14 +36,7 @@ namespace Ordering.BackgroundTasks.Services
|
|||||||
_logger.LogDebug("GracePeriodManagerService background task is doing background work.");
|
_logger.LogDebug("GracePeriodManagerService background task is doing background work.");
|
||||||
|
|
||||||
CheckConfirmedGracePeriodOrders();
|
CheckConfirmedGracePeriodOrders();
|
||||||
try
|
await Task.Delay(_settings.CheckUpdateTime, stoppingToken);
|
||||||
{
|
|
||||||
await Task.Delay(_settings.CheckUpdateTime, stoppingToken);
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException exception)
|
|
||||||
{
|
|
||||||
_logger.LogCritical(exception, "TaskCanceledException Error", exception.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("GracePeriodManagerService background task is stopping.");
|
_logger.LogDebug("GracePeriodManagerService background task is stopping.");
|
||||||
@ -59,7 +52,7 @@ namespace Ordering.BackgroundTasks.Services
|
|||||||
{
|
{
|
||||||
var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
|
var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
|
||||||
|
|
||||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, Program.AppName, confirmGracePeriodEvent);
|
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, confirmGracePeriodEvent);
|
||||||
|
|
||||||
_eventBus.Publish(confirmGracePeriodEvent);
|
_eventBus.Publish(confirmGracePeriodEvent);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"SubscriptionClientName": "BackgroundTasks",
|
"SubscriptionClientName": "BackgroundTasks",
|
||||||
"GracePeriodTime": "1",
|
"GracePeriodTime": "1",
|
||||||
"CheckUpdateTime": "1000",
|
"CheckUpdateTime": "1000",
|
||||||
|
@ -3,40 +3,49 @@ using Microsoft.Extensions.Hosting;
|
|||||||
|
|
||||||
namespace Ordering.FunctionalTests;
|
namespace Ordering.FunctionalTests;
|
||||||
|
|
||||||
public class OrderingScenarioBase : WebApplicationFactory<Program>
|
public class OrderingScenarioBase
|
||||||
{
|
{
|
||||||
public TestServer CreateServer()
|
private class OrderingApplication : WebApplicationFactory<Program>
|
||||||
{
|
{
|
||||||
Services.MigrateDbContext<OrderingContext>((context, services) =>
|
public TestServer CreateServer()
|
||||||
{
|
{
|
||||||
var env = services.GetService<IWebHostEnvironment>();
|
Services.MigrateDbContext<OrderingContext>((context, services) =>
|
||||||
var settings = services.GetService<IOptions<OrderingSettings>>();
|
{
|
||||||
var logger = services.GetService<ILogger<OrderingContextSeed>>();
|
var env = services.GetService<IWebHostEnvironment>();
|
||||||
|
var settings = services.GetService<IOptions<OrderingSettings>>();
|
||||||
|
var logger = services.GetService<ILogger<OrderingContextSeed>>();
|
||||||
|
|
||||||
new OrderingContextSeed()
|
new OrderingContextSeed()
|
||||||
.SeedAsync(context, env, settings, logger)
|
.SeedAsync(context, env, settings, logger)
|
||||||
.Wait();
|
.Wait();
|
||||||
})
|
})
|
||||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||||
|
|
||||||
return Server;
|
return Server;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IHost CreateHost(IHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices(servies =>
|
||||||
|
{
|
||||||
|
servies.AddSingleton<IStartupFilter, AuthStartupFilter>();
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.ConfigureAppConfiguration(c =>
|
||||||
|
{
|
||||||
|
var directory = Path.GetDirectoryName(typeof(OrderingScenarioBase).Assembly.Location)!;
|
||||||
|
|
||||||
|
c.AddJsonFile(Path.Combine(directory, "appsettings.json"), optional: false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return base.CreateHost(builder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IHost CreateHost(IHostBuilder builder)
|
public TestServer CreateServer()
|
||||||
{
|
{
|
||||||
builder.ConfigureServices(servies =>
|
var factory = new OrderingApplication();
|
||||||
{
|
return factory.CreateServer();
|
||||||
servies.AddSingleton<IStartupFilter, AuthStartupFilter>();
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.ConfigureAppConfiguration(c =>
|
|
||||||
{
|
|
||||||
var directory = Path.GetDirectoryName(typeof(OrderingScenarioBase).Assembly.Location)!;
|
|
||||||
|
|
||||||
c.AddJsonFile(Path.Combine(directory, "appsettings.json"), optional: false);
|
|
||||||
});
|
|
||||||
|
|
||||||
return base.CreateHost(builder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Get
|
public static class Get
|
||||||
|
@ -23,8 +23,7 @@ global using Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.AutofacMod
|
|||||||
global using Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
global using Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||||
global using Microsoft.eShopOnContainers.Services.Ordering.SignalrHub;
|
global using Microsoft.eShopOnContainers.Services.Ordering.SignalrHub;
|
||||||
global using RabbitMQ.Client;
|
global using RabbitMQ.Client;
|
||||||
global using Serilog.Context;
|
global using System.Collections.Generic;
|
||||||
global using Serilog;
|
|
||||||
global using System.IdentityModel.Tokens.Jwt;
|
global using System.IdentityModel.Tokens.Jwt;
|
||||||
global using System.IO;
|
global using System.IO;
|
||||||
global using System.Reflection;
|
global using System.Reflection;
|
||||||
|
@ -16,9 +16,9 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIn
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||||
|
|
||||||
public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToCancelledIntegrationEvent>
|
public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToCancelledIntegrationEvent>
|
||||||
{
|
{
|
||||||
@ -16,13 +18,13 @@ public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegration
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||||
|
|
||||||
public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
|
public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
|
||||||
{
|
{
|
||||||
@ -16,9 +18,9 @@ public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEvent
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
|
@ -13,12 +13,11 @@ public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEv
|
|||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||||
|
|
||||||
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
||||||
@ -17,9 +19,9 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||||
|
|
||||||
public class OrderStatusChangedToSubmittedIntegrationEventHandler :
|
public class OrderStatusChangedToSubmittedIntegrationEventHandler :
|
||||||
@ -17,9 +19,9 @@ public class OrderStatusChangedToSubmittedIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
await _hubContext.Clients
|
await _hubContext.Clients
|
||||||
.Group(@event.BuyerName)
|
.Group(@event.BuyerName)
|
||||||
|
@ -23,12 +23,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -8,7 +8,6 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory());
|
|||||||
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||||
builder.Configuration.AddEnvironmentVariables();
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
builder.WebHost.CaptureStartupErrors(false);
|
builder.WebHost.CaptureStartupErrors(false);
|
||||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
|
||||||
|
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddCustomHealthCheck(builder.Configuration)
|
.AddCustomHealthCheck(builder.Configuration)
|
||||||
@ -110,22 +109,8 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
|||||||
app.MapHub<NotificationsHub>("/hub/notificationhub");
|
app.MapHub<NotificationsHub>("/hub/notificationhub");
|
||||||
|
|
||||||
ConfigureEventBus(app);
|
ConfigureEventBus(app);
|
||||||
try
|
await app.RunAsync();
|
||||||
{
|
|
||||||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName);
|
|
||||||
await app.RunAsync();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
void ConfigureEventBus(IApplicationBuilder app)
|
void ConfigureEventBus(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||||
@ -137,6 +122,7 @@ void ConfigureEventBus(IApplicationBuilder app)
|
|||||||
eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>();
|
eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>();
|
||||||
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
|
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureAuthService(IServiceCollection services, IConfiguration configuration)
|
void ConfigureAuthService(IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
// prevent from mapping "sub" claim to nameidentifier.
|
// prevent from mapping "sub" claim to nameidentifier.
|
||||||
@ -210,20 +196,6 @@ void RegisterEventBus(IServiceCollection services, IConfiguration configuration)
|
|||||||
|
|
||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
}
|
}
|
||||||
static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
return new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
|
||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
{
|
{
|
||||||
"IdentityUrl": "http://localhost:5105",
|
"IdentityUrl": "http://localhost:5105",
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AzureServiceBusEnabled": false,
|
"AzureServiceBusEnabled": false,
|
||||||
"SubscriptionClientName": "Ordering.signalrhub",
|
"SubscriptionClientName": "Ordering.signalrhub",
|
||||||
"EventBusRetryCount": 5,
|
"EventBusRetryCount": 5,
|
||||||
|
@ -20,8 +20,6 @@ global using Microsoft.Extensions.Logging;
|
|||||||
global using Microsoft.eShopOnContainers.Payment.API.IntegrationEvents.EventHandling;
|
global using Microsoft.eShopOnContainers.Payment.API.IntegrationEvents.EventHandling;
|
||||||
global using Microsoft.eShopOnContainers.Payment.API;
|
global using Microsoft.eShopOnContainers.Payment.API;
|
||||||
global using RabbitMQ.Client;
|
global using RabbitMQ.Client;
|
||||||
global using Serilog.Context;
|
|
||||||
global using Serilog;
|
|
||||||
global using System.Threading.Tasks;
|
global using System.Threading.Tasks;
|
||||||
global using System;
|
global using System;
|
||||||
global using System.IO;
|
global using System.IO;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Payment.API.IntegrationEvents.EventHandling;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Payment.API.IntegrationEvents.EventHandling;
|
||||||
|
|
||||||
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
||||||
@ -21,9 +23,9 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
|||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
|
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IntegrationEventContext", @event.Id))
|
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||||
|
|
||||||
IntegrationEvent orderPaymentIntegrationEvent;
|
IntegrationEvent orderPaymentIntegrationEvent;
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
|||||||
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
|
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent);
|
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, orderPaymentIntegrationEvent);
|
||||||
|
|
||||||
_eventBus.Publish(orderPaymentIntegrationEvent);
|
_eventBus.Publish(orderPaymentIntegrationEvent);
|
||||||
|
|
||||||
|
@ -20,12 +20,6 @@
|
|||||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" />
|
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
{
|
|
||||||
Args = args,
|
|
||||||
ApplicationName = typeof(Program).Assembly.FullName,
|
|
||||||
ContentRootPath = Directory.GetCurrentDirectory()
|
|
||||||
});
|
|
||||||
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
||||||
{
|
{
|
||||||
TokenCredential credential = new ClientSecretCredential(
|
TokenCredential credential = new ClientSecretCredential(
|
||||||
@ -16,7 +11,6 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory());
|
|||||||
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||||
builder.Configuration.AddEnvironmentVariables();
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
builder.WebHost.CaptureStartupErrors(false);
|
builder.WebHost.CaptureStartupErrors(false);
|
||||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddCustomHealthCheck(builder.Configuration);
|
.AddCustomHealthCheck(builder.Configuration);
|
||||||
builder.Services.Configure<PaymentSettings>(builder.Configuration);
|
builder.Services.Configure<PaymentSettings>(builder.Configuration);
|
||||||
@ -88,22 +82,8 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
|||||||
{
|
{
|
||||||
Predicate = r => r.Name.Contains("self")
|
Predicate = r => r.Name.Contains("self")
|
||||||
});
|
});
|
||||||
try
|
|
||||||
{
|
|
||||||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName);
|
|
||||||
await app.RunAsync();
|
|
||||||
|
|
||||||
return 0;
|
await app.RunAsync();
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterEventBus(IServiceCollection services)
|
void RegisterEventBus(IServiceCollection services)
|
||||||
{
|
{
|
||||||
@ -149,21 +129,6 @@ void ConfigureEventBus(IApplicationBuilder app)
|
|||||||
eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
|
eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
return new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
||||||
|
@ -1,16 +1,4 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"PaymentSucceeded": true,
|
"PaymentSucceeded": true,
|
||||||
"AzureServiceBusEnabled": false,
|
"AzureServiceBusEnabled": false,
|
||||||
"SubscriptionClientName": "Payment",
|
"SubscriptionClientName": "Payment",
|
||||||
|
@ -16,7 +16,6 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Services.Common;
|
namespace Services.Common;
|
||||||
|
|
||||||
@ -33,11 +32,6 @@ public static class CommonExtensions
|
|||||||
// Default health checks assume the event bus and self health checks
|
// Default health checks assume the event bus and self health checks
|
||||||
builder.Services.AddDefaultHealthChecks(builder.Configuration);
|
builder.Services.AddDefaultHealthChecks(builder.Configuration);
|
||||||
|
|
||||||
// Configure the default logging for this application
|
|
||||||
// builder.Host.UseDefaultSerilog(builder.Configuration, builder.Environment.ApplicationName);
|
|
||||||
|
|
||||||
// Customizations for this application
|
|
||||||
|
|
||||||
// Add the event bus
|
// Add the event bus
|
||||||
builder.Services.AddEventBus(builder.Configuration);
|
builder.Services.AddEventBus(builder.Configuration);
|
||||||
|
|
||||||
@ -388,36 +382,6 @@ public static class CommonExtensions
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UseDefaultSerilog(this IHostBuilder builder, IConfiguration configuration, string name)
|
|
||||||
{
|
|
||||||
builder.UseSerilog(CreateSerilogLogger(configuration));
|
|
||||||
|
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
|
|
||||||
var loggingConfiguration = new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", name)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.ReadFrom.Configuration(configuration);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(seqServerUrl))
|
|
||||||
{
|
|
||||||
loggingConfiguration.WriteTo.Seq(seqServerUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(logstashUrl))
|
|
||||||
{
|
|
||||||
loggingConfiguration.WriteTo.Http(logstashUrl, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return loggingConfiguration.CreateLogger();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void MapDefaultHealthChecks(this IEndpointRouteBuilder routes)
|
public static void MapDefaultHealthChecks(this IEndpointRouteBuilder routes)
|
||||||
{
|
{
|
||||||
routes.MapHealthChecks("/hc", new HealthCheckOptions()
|
routes.MapHealthChecks("/hc", new HealthCheckOptions()
|
||||||
|
@ -41,12 +41,6 @@
|
|||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
||||||
<PackageReference Include="Polly" />
|
<PackageReference Include="Polly" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" />
|
||||||
<PackageReference Include="System.Data.SqlClient" />
|
<PackageReference Include="System.Data.SqlClient" />
|
||||||
|
@ -16,7 +16,7 @@ public class AccountController : Controller
|
|||||||
var user = User as ClaimsPrincipal;
|
var user = User as ClaimsPrincipal;
|
||||||
var token = await HttpContext.GetTokenAsync("access_token");
|
var token = await HttpContext.GetTokenAsync("access_token");
|
||||||
|
|
||||||
_logger.LogInformation("----- User {@User} authenticated into {AppName}", user, Program.AppName);
|
_logger.LogInformation("----- User {@User} authenticated", user);
|
||||||
|
|
||||||
if (token != null)
|
if (token != null)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
namespace WebMVC.Infrastructure;
|
namespace WebMVC.Infrastructure;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
public class WebContextSeed
|
public class WebContextSeed
|
||||||
{
|
{
|
||||||
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
|
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
var log = Log.Logger;
|
var settings = applicationBuilder
|
||||||
|
|
||||||
var settings = (AppSettings)applicationBuilder
|
|
||||||
.ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;
|
.ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;
|
||||||
|
var log = applicationBuilder.ApplicationServices.GetRequiredService<ILogger<WebContextSeed>>();
|
||||||
|
|
||||||
var useCustomizationData = settings.UseCustomizationData;
|
var useCustomizationData = settings.UseCustomizationData;
|
||||||
var contentRootPath = env.ContentRootPath;
|
var contentRootPath = env.ContentRootPath;
|
||||||
@ -29,7 +27,7 @@ public class WebContextSeed
|
|||||||
string overrideCssFile = Path.Combine(contentRootPath, "Setup", "override.css");
|
string overrideCssFile = Path.Combine(contentRootPath, "Setup", "override.css");
|
||||||
if (!File.Exists(overrideCssFile))
|
if (!File.Exists(overrideCssFile))
|
||||||
{
|
{
|
||||||
log.Error("Override css file '{FileName}' does not exists.", overrideCssFile);
|
log.LogError("Override css file '{FileName}' does not exists.", overrideCssFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +36,7 @@ public class WebContextSeed
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error(ex, "EXCEPTION ERROR: {Message}", ex.Message);
|
log.LogError(ex, "Error getting preconfigured css");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ public class WebContextSeed
|
|||||||
string imagesZipFile = Path.Combine(contentRootPath, "Setup", "images.zip");
|
string imagesZipFile = Path.Combine(contentRootPath, "Setup", "images.zip");
|
||||||
if (!File.Exists(imagesZipFile))
|
if (!File.Exists(imagesZipFile))
|
||||||
{
|
{
|
||||||
log.Error("Zip file '{ZipFileName}' does not exists.", imagesZipFile);
|
log.LogError("Zip file '{ZipFileName}' does not exists.", imagesZipFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +68,14 @@ public class WebContextSeed
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Warning("Skipped file '{FileName}' in zipfile '{ZipFileName}'", entry.Name, imagesZipFile);
|
log.LogWarning("Skipped file '{FileName}' in zip file '{ZipFileName}'", entry.Name, imagesZipFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error(ex, "EXCEPTION ERROR: {Message}", ex.Message);
|
log.LogError(ex, "Error getting preconfigured images");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ AddHttpClientServices(builder);
|
|||||||
AddCustomAuthentication(builder);
|
AddCustomAuthentication(builder);
|
||||||
|
|
||||||
builder.WebHost.CaptureStartupErrors(false);
|
builder.WebHost.CaptureStartupErrors(false);
|
||||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -58,26 +57,6 @@ app.MapHealthChecks("/hc", new HealthCheckOptions()
|
|||||||
|
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
var cfg = new LoggerConfiguration()
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.Enrich.WithProperty("ApplicationContext", AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console();
|
|
||||||
if (!string.IsNullOrWhiteSpace(seqServerUrl))
|
|
||||||
{
|
|
||||||
cfg.WriteTo.Seq(seqServerUrl);
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrWhiteSpace(logstashUrl))
|
|
||||||
{
|
|
||||||
cfg.WriteTo.Http(logstashUrl, null);
|
|
||||||
}
|
|
||||||
return cfg.CreateLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AddApplicationInsights(WebApplicationBuilder builder)
|
static void AddApplicationInsights(WebApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
||||||
@ -174,4 +153,4 @@ static void AddCustomAuthentication(WebApplicationBuilder builder)
|
|||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
public static readonly string AppName = typeof(Program).Assembly.GetName().Name;
|
public static readonly string AppName = typeof(Program).Assembly.GetName().Name;
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,6 @@
|
|||||||
<PackageReference Include="Microsoft.Build.Utilities.Core" />
|
<PackageReference Include="Microsoft.Build.Utilities.Core" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Debug"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,6 @@
|
|||||||
"UseLoadTest": false,
|
"UseLoadTest": false,
|
||||||
"ActivateCampaignDetailFunction": "False",
|
"ActivateCampaignDetailFunction": "False",
|
||||||
"UseCustomizationData": false,
|
"UseCustomizationData": false,
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"InstrumentationKey": ""
|
"InstrumentationKey": ""
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,6 @@ global using Microsoft.Extensions.Hosting;
|
|||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Microsoft.IdentityModel.Logging;
|
global using Microsoft.IdentityModel.Logging;
|
||||||
global using Serilog;
|
|
||||||
global using StackExchange.Redis;
|
global using StackExchange.Redis;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
global using System.ComponentModel.DataAnnotations;
|
global using System.ComponentModel.DataAnnotations;
|
||||||
@ -46,4 +45,4 @@ global using System.Threading.Tasks;
|
|||||||
global using System.Threading;
|
global using System.Threading;
|
||||||
global using System;
|
global using System;
|
||||||
global using WebMVC.Infrastructure;
|
global using WebMVC.Infrastructure;
|
||||||
global using WebMVC.Services.ModelDTOs;
|
global using WebMVC.Services.ModelDTOs;
|
||||||
|
@ -3,7 +3,6 @@ global using Microsoft.AspNetCore;
|
|||||||
global using Microsoft.AspNetCore.Hosting;
|
global using Microsoft.AspNetCore.Hosting;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Serilog;
|
|
||||||
global using System.IO;
|
global using System.IO;
|
||||||
global using eShopOnContainers.WebSPA;
|
global using eShopOnContainers.WebSPA;
|
||||||
global using HealthChecks.UI.Client;
|
global using HealthChecks.UI.Client;
|
||||||
|
@ -37,16 +37,6 @@ builder.Services.AddSpaStaticFiles(configuration =>
|
|||||||
|
|
||||||
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
|
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
|
||||||
builder.Logging.AddAzureWebAppDiagnostics();
|
builder.Logging.AddAzureWebAppDiagnostics();
|
||||||
builder.Host.UseSerilog((builderContext, config) =>
|
|
||||||
{
|
|
||||||
config
|
|
||||||
.MinimumLevel.Information()
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Seq("http://seq")
|
|
||||||
.ReadFrom.Configuration(builderContext.Configuration)
|
|
||||||
.WriteTo.Console();
|
|
||||||
})
|
|
||||||
.UseConsoleLifetime();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -42,9 +42,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||||
<PackageReference Include="Newtonsoft.Json" />
|
<PackageReference Include="Newtonsoft.Json" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
|
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
global using Microsoft.AspNetCore.Mvc;
|
global using Microsoft.AspNetCore.Mvc;
|
||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using System.Linq;
|
global using System.Linq;
|
||||||
global using Microsoft.AspNetCore;
|
|
||||||
global using Microsoft.AspNetCore.Hosting;
|
global using Microsoft.AspNetCore.Hosting;
|
||||||
global using Serilog;
|
|
||||||
global using System;
|
global using System;
|
||||||
global using System.Collections.Generic;
|
global using System.Collections.Generic;
|
||||||
global using System.IO;
|
|
||||||
global using System.Reflection;
|
|
||||||
global using WebStatus;
|
|
||||||
global using Azure.Identity;
|
global using Azure.Identity;
|
||||||
global using Azure.Core;
|
global using Azure.Core;
|
||||||
global using Microsoft.AspNetCore.Builder;
|
global using Microsoft.AspNetCore.Builder;
|
||||||
@ -16,4 +11,3 @@ global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.Diagnostics.HealthChecks;
|
global using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
global using Microsoft.Extensions.Hosting;
|
global using Microsoft.Extensions.Hosting;
|
||||||
global using Microsoft.Extensions.Logging;
|
|
||||||
|
@ -1,83 +1,60 @@
|
|||||||
try
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
TokenCredential credential = new ClientSecretCredential(
|
||||||
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
builder.Configuration["Vault:TenantId"],
|
||||||
{
|
builder.Configuration["Vault:ClientId"],
|
||||||
TokenCredential credential = new ClientSecretCredential(
|
builder.Configuration["Vault:ClientSecret"]);
|
||||||
builder.Configuration["Vault:TenantId"],
|
builder.Configuration.AddAzureKeyVault(new Uri($"https://{builder.Configuration["Vault:Name"]}.vault.azure.net/"), credential);
|
||||||
builder.Configuration["Vault:ClientId"],
|
|
||||||
builder.Configuration["Vault:ClientSecret"]);
|
|
||||||
builder.Configuration.AddAzureKeyVault(new Uri($"https://{builder.Configuration["Vault:Name"]}.vault.azure.net/"), credential);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Host.UseSerilog(CreateLogger(builder.Configuration));
|
|
||||||
builder.WebHost.CaptureStartupErrors(false);
|
|
||||||
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
|
||||||
builder.Services.AddApplicationInsightsKubernetesEnricher();
|
|
||||||
builder.Services.AddMvc();
|
|
||||||
builder.Services.AddOptions();
|
|
||||||
builder.Services.AddHealthChecks()
|
|
||||||
.AddCheck("self", () => HealthCheckResult.Healthy());
|
|
||||||
builder.Services
|
|
||||||
.AddHealthChecksUI()
|
|
||||||
.AddInMemoryStorage();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
app.UseExceptionHandler("/Home/Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
var pathBase = app.Configuration["PATH_BASE"];
|
|
||||||
if (!string.IsNullOrEmpty(pathBase))
|
|
||||||
{
|
|
||||||
app.UsePathBase(pathBase);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.UseHealthChecksUI(config =>
|
|
||||||
{
|
|
||||||
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
|
||||||
config.UIPath = "/hc-ui";
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseStaticFiles();
|
|
||||||
|
|
||||||
app.UseRouting();
|
|
||||||
app.MapDefaultControllerRoute();
|
|
||||||
app.MapHealthChecks("/liveness", new HealthCheckOptions
|
|
||||||
{
|
|
||||||
Predicate = r => r.Name.Contains("self")
|
|
||||||
});
|
|
||||||
|
|
||||||
await app.RunAsync();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serilog.ILogger CreateLogger(IConfiguration configuration)
|
builder.WebHost.CaptureStartupErrors(false);
|
||||||
|
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
||||||
|
builder.Services.AddApplicationInsightsKubernetesEnricher();
|
||||||
|
builder.Services.AddMvc();
|
||||||
|
builder.Services.AddOptions();
|
||||||
|
builder.Services.AddHealthChecks()
|
||||||
|
.AddCheck("self", () => HealthCheckResult.Healthy());
|
||||||
|
builder.Services
|
||||||
|
.AddHealthChecksUI()
|
||||||
|
.AddInMemoryStorage();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
app.UseDeveloperExceptionPage();
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
|
||||||
return new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Verbose()
|
|
||||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl, null)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseExceptionHandler("/Home/Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
var pathBase = app.Configuration["PATH_BASE"];
|
||||||
|
if (!string.IsNullOrEmpty(pathBase))
|
||||||
|
{
|
||||||
|
app.UsePathBase(pathBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHealthChecksUI(config =>
|
||||||
|
{
|
||||||
|
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
||||||
|
config.UIPath = "/hc-ui";
|
||||||
|
});
|
||||||
|
|
||||||
|
app.UseStaticFiles();
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
app.MapDefaultControllerRoute();
|
||||||
|
app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||||
|
{
|
||||||
|
Predicate = r => r.Name.Contains("self")
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.RunAsync();
|
||||||
|
|
||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
private static readonly string _namespace = typeof(Program).Assembly.GetName().Name;
|
private static readonly string _namespace = typeof(Program).Assembly.GetName().Name;
|
||||||
public static readonly string AppName = _namespace;
|
public static readonly string AppName = _namespace;
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" />
|
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Http" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Debug"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,4 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
|
||||||
"SeqServerUrl": null,
|
|
||||||
"LogstashgUrl": null,
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.eShopOnContainers": "Information",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Webhooks": [
|
"Webhooks": [
|
||||||
{
|
{
|
||||||
"Name": "",
|
"Name": "",
|
||||||
|
@ -117,8 +117,6 @@ services:
|
|||||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||||
- UseLoadTest=${USE_LOADTEST:-False}
|
- UseLoadTest=${USE_LOADTEST:-False}
|
||||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
|
||||||
- Serilog__MinimumLevel__Override__ordering-api=Verbose
|
|
||||||
- PATH_BASE=/ordering-api
|
- PATH_BASE=/ordering-api
|
||||||
- GRPC_PORT=81
|
- GRPC_PORT=81
|
||||||
- PORT=80
|
- PORT=80
|
||||||
@ -141,7 +139,6 @@ services:
|
|||||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||||
- UseLoadTest=${USE_LOADTEST:-False}
|
- UseLoadTest=${USE_LOADTEST:-False}
|
||||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
|
||||||
ports:
|
ports:
|
||||||
- "5111:80"
|
- "5111:80"
|
||||||
|
|
||||||
@ -155,8 +152,6 @@ services:
|
|||||||
- AzureServiceBusEnabled=False
|
- AzureServiceBusEnabled=False
|
||||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||||
- Serilog__MinimumLevel__Override__payment-api.IntegrationEvents.EventHandling=Verbose
|
|
||||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
|
||||||
ports:
|
ports:
|
||||||
- "5108:80"
|
- "5108:80"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user