Browse Source

Updated logging

pull/85/head
Galip Tolga Erdem 5 years ago
parent
commit
fb46286b92
  1. 38
      services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs
  2. 4
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs
  3. 8
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs
  4. 10
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs
  5. 6
      services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs
  6. 6
      shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs

38
services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.DistributedLocking;
@ -15,7 +16,7 @@ using Volo.Abp.Uow;
namespace EShopOnAbp.AdministrationService.DbMigrations
{
public class AdministrationServiceDatabaseMigrationEventHandler
: DatabaseEfCoreMigrationEventHandler<AdministrationServiceDbContext>,
: DatabaseEfCoreMigrationEventHandler<AdministrationServiceDbContext>,
IDistributedEventHandler<TenantCreatedEto>,
IDistributedEventHandler<ApplyDatabaseMigrationsEto>
{
@ -37,7 +38,7 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
distributedEventBus,
AdministrationServiceDbProperties.ConnectionStringName,
distributedLockProvider
)
)
{
_permissionDefinitionManager = permissionDefinitionManager;
_permissionDataSeeder = permissionDataSeeder;
@ -45,8 +46,6 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData)
{
Logger.LogInformation("AdministrationService - HandleEventAsync started ...");
if (eventData.DatabaseName != DatabaseName)
{
return;
@ -54,8 +53,16 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
try
{
await MigrateDatabaseSchemaAsync(eventData.TenantId);
await SeedDataAsync(eventData.TenantId);
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
Log.Information("AdministrationService acquired lock for db migration and seeding...");
if (handle != null)
{
await MigrateDatabaseSchemaAsync(eventData.TenantId);
await SeedDataAsync(eventData.TenantId);
}
}
}
catch (Exception ex)
{
@ -67,17 +74,9 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
{
try
{
Logger.LogInformation("AdministrationService - Before Acquire and Migration and Seed Data");
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
if (handle != null)
{
await MigrateDatabaseSchemaAsync(eventData.Id);
Logger.LogInformation("Starting AdministrationService DataSeeder...");
await SeedDataAsync(eventData.Id);
}
}
await MigrateDatabaseSchemaAsync(eventData.Id);
Logger.LogInformation("Starting AdministrationService DataSeeder...");
await SeedDataAsync(eventData.Id);
}
catch (Exception ex)
{
@ -98,7 +97,8 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
var permissionNames = _permissionDefinitionManager
.GetPermissions()
.Where(p => p.MultiTenancySide.HasFlag(multiTenancySide))
.Where(p => !p.Providers.Any() || p.Providers.Contains(RolePermissionValueProvider.ProviderName))
.Where(p => !p.Providers.Any() ||
p.Providers.Contains(RolePermissionValueProvider.ProviderName))
.Select(p => p.Name)
.ToArray();
@ -114,4 +114,4 @@ namespace EShopOnAbp.AdministrationService.DbMigrations
}
}
}
}
}

4
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs

@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Serilog;
using Volo.Abp.Data;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Distributed;
@ -47,12 +48,13 @@ namespace EShopOnAbp.CatalogService.DbMigrations
try
{
Logger.LogInformation("CatalogService - Before Acquire and MigrateDatabaseSchemaAsync");
Log.Information("CatalogService has acquired lock for db migration...");
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
if (handle != null)
{
Log.Information("CatalogService is migrating database...");
await MigrateDatabaseSchemaAsync(null);
}
}

8
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs

@ -56,14 +56,15 @@ namespace EShopOnAbp.IdentityService.DbMigrations
try
{
Logger.LogInformation("IdentityService - Before Acquire ");
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
Log.Information("IdentityService has acquired lock for db migration...");
if (handle != null)
{
Log.Information("IdentityService is migrating database...");
await MigrateDatabaseSchemaAsync(eventData.TenantId);
Logger.LogInformation("Starting IdentityService DataSeeder...");
Log.Information("IdentityService is seeding data...");
await SeedDataAsync(
tenantId: eventData.TenantId,
adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress,
@ -78,7 +79,6 @@ namespace EShopOnAbp.IdentityService.DbMigrations
{
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex);
}
}
public async Task HandleEventAsync(TenantCreatedEto eventData)

10
services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs

@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Serilog;
using Volo.Abp.Data;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Distributed;
@ -37,8 +38,6 @@ namespace EShopOnAbp.OrderingService.DbMigrations
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData)
{
Logger.LogInformation("OrderingService - HandleEventAsync started ...");
if (eventData.DatabaseName != DatabaseName)
{
return;
@ -51,14 +50,15 @@ namespace EShopOnAbp.OrderingService.DbMigrations
try
{
Logger.LogInformation("OrderingService - Before Acquire ");
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
Log.Information("OrderingService has acquired lock for db migration...");
if (handle != null)
{
Log.Information("OrderingService is migrating database...");
await MigrateDatabaseSchemaAsync(null);
Logger.LogInformation("Starting OrderingService DataSeeder...");
Log.Information("OrderingService is seeding data...");
await _dataSeeder.SeedAsync();
}
}

6
services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs

@ -3,6 +3,7 @@ using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Serilog;
using Volo.Abp.Data;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Distributed;
@ -45,15 +46,14 @@ namespace EShopOnAbp.PaymentService.DbMigrations
try
{
Logger.LogInformation("PaymentService - Before Acquire and MigrateDatabaseSchemaAsync");
Log.Information("PaymentService has acquired lock for db migration...");
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
{
if (handle != null)
{
Log.Information("PaymentService is migrating database...");
await MigrateDatabaseSchemaAsync(null);
Logger.LogInformation("PaymentService No Seed...");
}
}
}

6
shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs

@ -82,7 +82,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler<TDbContext> : Database
if (tenantId == null)
{
//Migrating the host database
Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is null");
Log.Information($"There is no tenant. Migrating {DatabaseName}...");
result = await MigrateDatabaseSchemaWithDbContextAsync();
}
else
@ -92,7 +92,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler<TDbContext> : Database
!tenantConfiguration.ConnectionStrings.GetOrDefault(DatabaseName).IsNullOrWhiteSpace())
{
//Migrating the tenant database (only if tenant has a separate database)
Logger.LogInformation($"{DatabaseName} MigrateDatabase in Shared - TenantId is not null");
Log.Information($"Migrating tenant database:{DatabaseName} with tenantId:{tenantId}...");
result = await MigrateDatabaseSchemaWithDbContextAsync();
}
}
@ -134,7 +134,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler<TDbContext> : Database
var tryCount = IncrementEventTryCount(eventData);
if (tryCount <= MaxEventTryCount)
{
Logger.LogWarning(
Log.Warning(
$"Could not perform tenant created event. Re-queueing the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}.");
Logger.LogException(exception, LogLevel.Warning);

Loading…
Cancel
Save