Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Remove Serilog usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed May 9, 2023
1 parent 5342c86 commit 8da0a81
Show file tree
Hide file tree
Showing 72 changed files with 174 additions and 664 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
11 changes: 2 additions & 9 deletions src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
await BuildWebHost(args).RunAsync();
await BuildWebHost(args).RunAsync();
IWebHost BuildWebHost(string[] args) =>
WebHost
.CreateDefaultBuilder(args)
Expand All @@ -13,11 +13,4 @@ IWebHost BuildWebHost(string[] args) =>
});
})
.UseStartup<Startup>()
.UseSerilog((builderContext, config) =>
{
config
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console();
})
.Build();
.Build();
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public TestIntegrationEventHandler()
Handled = false;
}

public async Task Handle(TestIntegrationEvent @event)
public Task Handle(TestIntegrationEvent @event)
{
Handled = true;
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public TestIntegrationOtherEventHandler()
Handled = false;
}

public async Task Handle(TestIntegrationEvent @event)
public Task Handle(TestIntegrationEvent @event)
{
Handled = true;
return Task.CompletedTask;
}
}
}
6 changes: 0 additions & 6 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
1 change: 0 additions & 1 deletion src/Services/Basket/Basket.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
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;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public OrderStartedIntegrationEventHandler(

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ProductPriceChangedIntegrationEventHandler(

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);

Expand Down
10 changes: 0 additions & 10 deletions src/Services/Basket/Basket.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 0 additions & 6 deletions src/Services/Catalog/Catalog.API/Catalog.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
1 change: 0 additions & 1 deletion src/Services/Catalog/Catalog.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@
global using Microsoft.Extensions.Options;
global using Polly;
global using Polly.Retry;
global using Serilog.Context;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions src/Services/Catalog/Catalog.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 0 additions & 12 deletions src/Services/Catalog/Catalog.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions src/Services/Catalog/Catalog.API/web.config
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
11 changes: 0 additions & 11 deletions src/Services/Identity/Identity.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ await strategy.ExecuteAsync(async () =>
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public GracePeriodConfirmedIntegrationEventHandler(
/// <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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public OrderStockRejectedIntegrationEventHandler(

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public UserCheckoutAcceptedIntegrationEventHandler(
/// <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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task PublishEventsThroughEventBusAsync(Guid transactionId)

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
{
Expand All @@ -37,7 +37,7 @@ public async Task PublishEventsThroughEventBusAsync(Guid transactionId)
}
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions src/Services/Ordering/Ordering.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
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;
Expand Down
9 changes: 3 additions & 6 deletions src/Services/Ordering/Ordering.API/Ordering.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
</Content>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Ordering.FunctionalTests"/>
</ItemGroup>

<ItemGroup>
<Protobuf Include="Proto\ordering.proto" GrpcServices="Server" Generator="MSBuild:Compile" />
Expand Down Expand Up @@ -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>
Expand Down
Loading

1 comment on commit 8da0a81

@LangSensei
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deprecate Serilog?

How about the usage of "@{object}" which will serialize the object automatically and written into log?

Please sign in to comment.