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.Options;
|
||||
global using Microsoft.OpenApi.Models;
|
||||
global using Serilog;
|
||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IdentityModel.Tokens.Jwt;
|
||||
|
@ -25,8 +25,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
|
||||
<PackageReference Include="Serilog.AspNetCore" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
await BuildWebHost(args).RunAsync();
|
||||
await BuildWebHost(args).RunAsync();
|
||||
IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost
|
||||
.CreateDefaultBuilder(args)
|
||||
@ -13,11 +13,4 @@ IWebHost BuildWebHost(string[] args) =>
|
||||
});
|
||||
})
|
||||
.UseStartup<Startup>()
|
||||
.UseSerilog((builderContext, config) =>
|
||||
{
|
||||
config
|
||||
.MinimumLevel.Information()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console();
|
||||
})
|
||||
.Build();
|
@ -12,9 +12,10 @@ namespace EventBus.Tests
|
||||
Handled = false;
|
||||
}
|
||||
|
||||
public async Task Handle(TestIntegrationEvent @event)
|
||||
public Task Handle(TestIntegrationEvent @event)
|
||||
{
|
||||
Handled = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,10 @@ namespace EventBus.Tests
|
||||
Handled = false;
|
||||
}
|
||||
|
||||
public async Task Handle(TestIntegrationEvent @event)
|
||||
public Task Handle(TestIntegrationEvent @event)
|
||||
{
|
||||
Handled = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,12 +83,6 @@
|
||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageVersion Include="Polly" Version="7.2.3" />
|
||||
<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.Newtonsoft" Version="6.5.0" />
|
||||
<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.Hosting;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Serilog.Context;
|
||||
global using Services.Common;
|
||||
global using StackExchange.Redis;
|
||||
|
@ -15,7 +15,7 @@ public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<Orde
|
||||
|
||||
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);
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandl
|
||||
|
||||
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);
|
||||
|
||||
|
@ -1,14 +1,4 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.eShopOnContainers": "Debug",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"IdentityUrlExternal": "http://localhost:5105",
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"ConnectionString": "127.0.0.1",
|
||||
|
@ -60,12 +60,6 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
|
||||
<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.Newtonsoft" />
|
||||
<PackageReference Include="System.Data.SqlClient" />
|
||||
|
@ -44,4 +44,3 @@ global using Microsoft.Extensions.Logging;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Polly;
|
||||
global using Polly.Retry;
|
||||
global using Serilog.Context;
|
||||
|
@ -19,7 +19,7 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
|
||||
|
||||
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);
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class OrderStatusChangedToPaidIntegrationEventHandler :
|
||||
|
||||
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);
|
||||
|
||||
|
@ -14,10 +14,8 @@
|
||||
"launchUrl": "/swagger",
|
||||
"environmentVariables": {
|
||||
"ConnectionString": "server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
||||
"Serilog:LogstashgUrl": "http://locahost:8080",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"EventBusConnection": "localhost",
|
||||
"Serilog:SeqServerUrl": "http://locahost:5340"
|
||||
"EventBusConnection": "localhost"
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/",
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.eShopOnContainers": "Debug",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"EventBusConnection": "localhost"
|
||||
}
|
@ -1,17 +1,5 @@
|
||||
{
|
||||
"UseCustomizationData": false,
|
||||
"Serilog": {
|
||||
"SeqServerUrl": null,
|
||||
"LogstashgUrl": null,
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.eShopOnContainers": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AzureServiceBusEnabled": false,
|
||||
"AzureStorageEnabled": false,
|
||||
"ApplicationInsights": {
|
||||
|
@ -8,10 +8,8 @@
|
||||
<environmentVariables>
|
||||
<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="Serilog:LogstashgUrl" value="http://locahost:8080" />
|
||||
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||
<environmentVariable name="EventBusConnection" value="localhost" />
|
||||
<environmentVariable name="Serilog:SeqServerUrl" value="http://locahost:5340" />
|
||||
</environmentVariables>
|
||||
</aspNetCore>
|
||||
</system.webServer>
|
||||
|
@ -4,17 +4,6 @@
|
||||
"SpaClient": "http://localhost:5104",
|
||||
"XamarinCallback": "http://localhost:5105/xamarincallback",
|
||||
"UseCustomizationData": false,
|
||||
"Serilog": {
|
||||
"SeqServerUrl": null,
|
||||
"LogstashgUrl": null,
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFramework": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"InstrumentationKey": ""
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TReque
|
||||
Guid transactionId;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -23,9 +23,9 @@ public class GracePeriodConfirmedIntegrationEventHandler : IIntegrationEventHand
|
||||
/// <returns></returns>
|
||||
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);
|
||||
|
||||
|
@ -16,9 +16,9 @@ public class OrderPaymentFailedIntegrationEventHandler :
|
||||
|
||||
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);
|
||||
|
||||
|
@ -16,9 +16,9 @@ public class OrderPaymentSucceededIntegrationEventHandler :
|
||||
|
||||
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);
|
||||
|
||||
|
@ -16,9 +16,9 @@ public class OrderStockConfirmedIntegrationEventHandler :
|
||||
|
||||
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);
|
||||
|
||||
|
@ -14,9 +14,9 @@ public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandle
|
||||
|
||||
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
|
||||
.FindAll(c => !c.HasStock)
|
||||
|
@ -24,15 +24,15 @@ public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHand
|
||||
/// <returns></returns>
|
||||
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;
|
||||
|
||||
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,
|
||||
@event.State, @event.Country, @event.ZipCode,
|
||||
|
@ -27,7 +27,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
|
||||
|
||||
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
|
||||
{
|
||||
@ -37,7 +37,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
|
||||
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
|
||||
|
||||
public static class BasketItemExtensions
|
||||
{
|
||||
|
@ -64,8 +64,6 @@ global using Microsoft.OpenApi.Models;
|
||||
global using Polly.Retry;
|
||||
global using Polly;
|
||||
global using RabbitMQ.Client;
|
||||
global using Serilog.Context;
|
||||
global using Serilog;
|
||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Data.Common;
|
||||
|
@ -19,6 +19,9 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Ordering.FunctionalTests"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Proto\ordering.proto" GrpcServices="Server" Generator="MSBuild:Compile" />
|
||||
@ -60,12 +63,6 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<PackageReference Include="Microsoft.NETCore.Platforms" />
|
||||
<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.Newtonsoft" />
|
||||
</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
|
||||
.AddGrpc(options =>
|
||||
{
|
||||
options.EnableDetailedErrors = true;
|
||||
})
|
||||
.Services
|
||||
.AddApplicationInsights(builder.Configuration)
|
||||
.AddCustomMvc()
|
||||
.AddHealthChecks(builder.Configuration)
|
||||
.AddCustomDbContext(builder.Configuration)
|
||||
@ -58,41 +54,6 @@ var services = builder.Services;
|
||||
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)
|
||||
services.AddSingleton<IValidator<CancelOrderCommand>, CancelOrderCommandValidator>();
|
||||
services.AddSingleton<IValidator<CreateOrderCommand>, CreateOrderCommandValidator>();
|
||||
@ -135,13 +96,12 @@ if (!string.IsNullOrEmpty(pathBase))
|
||||
{
|
||||
app.UsePathBase(pathBase);
|
||||
}
|
||||
app.UseSwagger()
|
||||
.UseSwaggerUI(c =>
|
||||
{
|
||||
app.UseSwagger().UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json", "Ordering.API V1");
|
||||
c.OAuthClientId("orderingswaggerui");
|
||||
c.OAuthAppName("Ordering Swagger UI");
|
||||
});
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseCors("CorsPolicy");
|
||||
@ -174,10 +134,9 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
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 env = app.Services.GetService<IWebHostEnvironment>();
|
||||
var settings = app.Services.GetService<IOptions<OrderingSettings>>();
|
||||
@ -187,21 +146,10 @@ try
|
||||
await new OrderingContextSeed().SeedAsync(context, env, settings, logger);
|
||||
var integEventContext = scope.ServiceProvider.GetRequiredService<IntegrationEventLogContext>();
|
||||
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)
|
||||
{
|
||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||
@ -213,37 +161,9 @@ void ConfigureEventBus(IApplicationBuilder app)
|
||||
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
||||
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
|
||||
{
|
||||
public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddApplicationInsightsTelemetry(configuration);
|
||||
services.AddApplicationInsightsKubernetesEnricher();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCustomMvc(this IServiceCollection 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",
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"UseCustomizationData": false,
|
||||
"Serilog": {
|
||||
"SeqServerUrl": null,
|
||||
"LogstashgUrl": null,
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.eShopOnContainers": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AzureServiceBusEnabled": false,
|
||||
"SubscriptionClientName": "Ordering",
|
||||
"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.EventBusRabbitMQ;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RabbitMQ.Client;
|
||||
using Serilog;
|
||||
|
||||
namespace Ordering.BackgroundTasks.Extensions
|
||||
{
|
||||
@ -120,23 +115,5 @@ namespace Ordering.BackgroundTasks.Extensions
|
||||
|
||||
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.Hosting;
|
||||
global using Ordering.BackgroundTasks.Extensions;
|
||||
global using Serilog;
|
||||
global using System.IO;
|
||||
global using HealthChecks.UI.Client;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Ordering.BackgroundTasks.Extensions;
|
||||
global using Ordering.BackgroundTasks.Services;
|
||||
global using System;
|
||||
global using Ordering.BackgroundTasks;
|
@ -18,12 +18,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
var appName = "Ordering.BackgroundTasks";
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
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.{builder.Environment.EnvironmentName}.json", optional: true);
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
||||
builder.Services.AddCustomHealthCheck(builder.Configuration)
|
||||
.Configure<BackgroundTaskSettings>(builder.Configuration)
|
||||
.AddOptions()
|
||||
@ -35,37 +33,7 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
await app.RunAsync();
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
|
@ -36,15 +36,8 @@ namespace Ordering.BackgroundTasks.Services
|
||||
_logger.LogDebug("GracePeriodManagerService background task is doing background work.");
|
||||
|
||||
CheckConfirmedGracePeriodOrders();
|
||||
try
|
||||
{
|
||||
await Task.Delay(_settings.CheckUpdateTime, stoppingToken);
|
||||
}
|
||||
catch (TaskCanceledException exception)
|
||||
{
|
||||
_logger.LogCritical(exception, "TaskCanceledException Error", exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogDebug("GracePeriodManagerService background task is stopping.");
|
||||
}
|
||||
@ -59,7 +52,7 @@ namespace Ordering.BackgroundTasks.Services
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -1,17 +1,5 @@
|
||||
{
|
||||
"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",
|
||||
"GracePeriodTime": "1",
|
||||
"CheckUpdateTime": "1000",
|
||||
|
@ -3,8 +3,10 @@ using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Ordering.FunctionalTests;
|
||||
|
||||
public class OrderingScenarioBase : WebApplicationFactory<Program>
|
||||
public class OrderingScenarioBase
|
||||
{
|
||||
private class OrderingApplication : WebApplicationFactory<Program>
|
||||
{
|
||||
public TestServer CreateServer()
|
||||
{
|
||||
Services.MigrateDbContext<OrderingContext>((context, services) =>
|
||||
@ -38,6 +40,13 @@ public class OrderingScenarioBase : WebApplicationFactory<Program>
|
||||
|
||||
return base.CreateHost(builder);
|
||||
}
|
||||
}
|
||||
|
||||
public TestServer CreateServer()
|
||||
{
|
||||
var factory = new OrderingApplication();
|
||||
return factory.CreateServer();
|
||||
}
|
||||
|
||||
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;
|
||||
global using RabbitMQ.Client;
|
||||
global using Serilog.Context;
|
||||
global using Serilog;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IdentityModel.Tokens.Jwt;
|
||||
global using System.IO;
|
||||
global using System.Reflection;
|
||||
|
@ -16,9 +16,9 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIn
|
||||
|
||||
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
|
||||
.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>
|
||||
{
|
||||
@ -16,9 +18,9 @@ public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegration
|
||||
|
||||
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
|
||||
.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 OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
|
||||
{
|
||||
@ -16,9 +18,9 @@ public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEvent
|
||||
|
||||
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
|
||||
.Group(@event.BuyerName)
|
||||
|
@ -13,12 +13,11 @@ public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEv
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
.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 :
|
||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
||||
@ -17,9 +19,9 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||
|
||||
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
|
||||
.Group(@event.BuyerName)
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling;
|
||||
|
||||
public class OrderStatusChangedToSubmittedIntegrationEventHandler :
|
||||
@ -17,9 +19,9 @@ public class OrderStatusChangedToSubmittedIntegrationEventHandler :
|
||||
|
||||
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
|
||||
.Group(@event.BuyerName)
|
||||
|
@ -23,12 +23,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<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>
|
||||
|
@ -8,7 +8,6 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory());
|
||||
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
builder.WebHost.CaptureStartupErrors(false);
|
||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
||||
|
||||
builder.Services
|
||||
.AddCustomHealthCheck(builder.Configuration)
|
||||
@ -110,22 +109,8 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
app.MapHub<NotificationsHub>("/hub/notificationhub");
|
||||
|
||||
ConfigureEventBus(app);
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||
@ -137,6 +122,7 @@ void ConfigureEventBus(IApplicationBuilder app)
|
||||
eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>();
|
||||
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
|
||||
}
|
||||
|
||||
void ConfigureAuthService(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
// prevent from mapping "sub" claim to nameidentifier.
|
||||
@ -210,20 +196,6 @@ void RegisterEventBus(IServiceCollection services, IConfiguration configuration)
|
||||
|
||||
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 static string Namespace = typeof(Program).Assembly.GetName().Name;
|
||||
|
@ -1,17 +1,5 @@
|
||||
{
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"Serilog": {
|
||||
"SeqServerUrl": null,
|
||||
"LogstashgUrl": null,
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.eShopOnContainers": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AzureServiceBusEnabled": false,
|
||||
"SubscriptionClientName": "Ordering.signalrhub",
|
||||
"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;
|
||||
global using RabbitMQ.Client;
|
||||
global using Serilog.Context;
|
||||
global using Serilog;
|
||||
global using System.Threading.Tasks;
|
||||
global using System;
|
||||
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 :
|
||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
||||
@ -21,9 +23,9 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||
|
||||
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;
|
||||
|
||||
@ -42,7 +44,7 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||
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);
|
||||
|
||||
|
@ -20,12 +20,6 @@
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||
<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>
|
||||
|
@ -1,9 +1,4 @@
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
ApplicationName = typeof(Program).Assembly.FullName,
|
||||
ContentRootPath = Directory.GetCurrentDirectory()
|
||||
});
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
||||
{
|
||||
TokenCredential credential = new ClientSecretCredential(
|
||||
@ -16,7 +11,6 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory());
|
||||
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
builder.WebHost.CaptureStartupErrors(false);
|
||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
||||
builder.Services
|
||||
.AddCustomHealthCheck(builder.Configuration);
|
||||
builder.Services.Configure<PaymentSettings>(builder.Configuration);
|
||||
@ -88,22 +82,8 @@ app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
{
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
await app.RunAsync();
|
||||
|
||||
void RegisterEventBus(IServiceCollection services)
|
||||
{
|
||||
@ -149,21 +129,6 @@ void ConfigureEventBus(IApplicationBuilder app)
|
||||
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 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,
|
||||
"AzureServiceBusEnabled": false,
|
||||
"SubscriptionClientName": "Payment",
|
||||
|
@ -16,7 +16,6 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using RabbitMQ.Client;
|
||||
using Serilog;
|
||||
|
||||
namespace Services.Common;
|
||||
|
||||
@ -33,11 +32,6 @@ public static class CommonExtensions
|
||||
// Default health checks assume the event bus and self health checks
|
||||
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
|
||||
builder.Services.AddEventBus(builder.Configuration);
|
||||
|
||||
@ -388,36 +382,6 @@ public static class CommonExtensions
|
||||
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)
|
||||
{
|
||||
routes.MapHealthChecks("/hc", new HealthCheckOptions()
|
||||
|
@ -41,12 +41,6 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
|
||||
<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.Newtonsoft" />
|
||||
<PackageReference Include="System.Data.SqlClient" />
|
||||
|
@ -16,7 +16,7 @@ public class AccountController : Controller
|
||||
var user = User as ClaimsPrincipal;
|
||||
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)
|
||||
{
|
||||
|
@ -1,14 +1,12 @@
|
||||
namespace WebMVC.Infrastructure;
|
||||
using Serilog;
|
||||
|
||||
public class WebContextSeed
|
||||
{
|
||||
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
|
||||
{
|
||||
var log = Log.Logger;
|
||||
|
||||
var settings = (AppSettings)applicationBuilder
|
||||
var settings = applicationBuilder
|
||||
.ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;
|
||||
var log = applicationBuilder.ApplicationServices.GetRequiredService<ILogger<WebContextSeed>>();
|
||||
|
||||
var useCustomizationData = settings.UseCustomizationData;
|
||||
var contentRootPath = env.ContentRootPath;
|
||||
@ -29,7 +27,7 @@ public class WebContextSeed
|
||||
string overrideCssFile = Path.Combine(contentRootPath, "Setup", "override.css");
|
||||
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;
|
||||
}
|
||||
|
||||
@ -38,7 +36,7 @@ public class WebContextSeed
|
||||
}
|
||||
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");
|
||||
if (!File.Exists(imagesZipFile))
|
||||
{
|
||||
log.Error("Zip file '{ZipFileName}' does not exists.", imagesZipFile);
|
||||
log.LogError("Zip file '{ZipFileName}' does not exists.", imagesZipFile);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -70,13 +68,13 @@ public class WebContextSeed
|
||||
}
|
||||
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)
|
||||
{
|
||||
log.Error(ex, "EXCEPTION ERROR: {Message}", ex.Message);
|
||||
log.LogError(ex, "Error getting preconfigured images");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ AddHttpClientServices(builder);
|
||||
AddCustomAuthentication(builder);
|
||||
|
||||
builder.WebHost.CaptureStartupErrors(false);
|
||||
builder.Host.UseSerilog(CreateSerilogLogger(builder.Configuration));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@ -58,26 +57,6 @@ app.MapHealthChecks("/hc", new HealthCheckOptions()
|
||||
|
||||
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)
|
||||
{
|
||||
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
|
||||
|
@ -35,12 +35,6 @@
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<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>
|
||||
|
@ -1,7 +1,2 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,6 @@
|
||||
"UseLoadTest": false,
|
||||
"ActivateCampaignDetailFunction": "False",
|
||||
"UseCustomizationData": false,
|
||||
"Serilog": {
|
||||
"SeqServerUrl": null,
|
||||
"LogstashgUrl": null,
|
||||
"MinimumLevel": {
|
||||
"Default": "Information"
|
||||
}
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"InstrumentationKey": ""
|
||||
},
|
||||
|
@ -26,7 +26,6 @@ global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Microsoft.IdentityModel.Logging;
|
||||
global using Serilog;
|
||||
global using StackExchange.Redis;
|
||||
global using System.Collections.Generic;
|
||||
global using System.ComponentModel.DataAnnotations;
|
||||
|
@ -3,7 +3,6 @@ global using Microsoft.AspNetCore;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Serilog;
|
||||
global using System.IO;
|
||||
global using eShopOnContainers.WebSPA;
|
||||
global using HealthChecks.UI.Client;
|
||||
|
@ -37,16 +37,6 @@ builder.Services.AddSpaStaticFiles(configuration =>
|
||||
|
||||
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
|
||||
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();
|
||||
|
||||
|
@ -42,9 +42,6 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="Serilog.AspNetCore" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" />
|
||||
</ItemGroup>
|
||||
|
||||
<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.Extensions.Configuration;
|
||||
global using System.Linq;
|
||||
global using Microsoft.AspNetCore;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Serilog;
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Reflection;
|
||||
global using WebStatus;
|
||||
global using Azure.Identity;
|
||||
global using Azure.Core;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
@ -16,4 +11,3 @@ global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
|
@ -1,80 +1,57 @@
|
||||
try
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
if (builder.Configuration.GetValue<bool>("UseVault", false))
|
||||
{
|
||||
TokenCredential credential = new ClientSecretCredential(
|
||||
builder.Configuration["Vault:TenantId"],
|
||||
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()
|
||||
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
|
||||
builder.Services
|
||||
.AddHealthChecksUI()
|
||||
.AddInMemoryStorage();
|
||||
|
||||
var app = builder.Build();
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
}
|
||||
|
||||
var pathBase = app.Configuration["PATH_BASE"];
|
||||
if (!string.IsNullOrEmpty(pathBase))
|
||||
{
|
||||
var pathBase = app.Configuration["PATH_BASE"];
|
||||
if (!string.IsNullOrEmpty(pathBase))
|
||||
{
|
||||
app.UsePathBase(pathBase);
|
||||
}
|
||||
}
|
||||
|
||||
app.UseHealthChecksUI(config =>
|
||||
{
|
||||
app.UseHealthChecksUI(config =>
|
||||
{
|
||||
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
||||
config.UIPath = "/hc-ui";
|
||||
});
|
||||
});
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
app.MapDefaultControllerRoute();
|
||||
app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
await app.RunAsync();
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
|
@ -19,12 +19,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
|
||||
<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>
|
||||
|
@ -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": [
|
||||
{
|
||||
"Name": "",
|
||||
|
@ -117,8 +117,6 @@ services:
|
||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||
- UseLoadTest=${USE_LOADTEST:-False}
|
||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
||||
- Serilog__MinimumLevel__Override__ordering-api=Verbose
|
||||
- PATH_BASE=/ordering-api
|
||||
- GRPC_PORT=81
|
||||
- PORT=80
|
||||
@ -141,7 +139,6 @@ services:
|
||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||
- UseLoadTest=${USE_LOADTEST:-False}
|
||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
||||
ports:
|
||||
- "5111:80"
|
||||
|
||||
@ -155,8 +152,6 @@ services:
|
||||
- AzureServiceBusEnabled=False
|
||||
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
|
||||
- OrchestratorType=${ORCHESTRATOR_TYPE}
|
||||
- Serilog__MinimumLevel__Override__payment-api.IntegrationEvents.EventHandling=Verbose
|
||||
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
|
||||
ports:
|
||||
- "5108:80"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user