fix: add class context to all loggers, format
This commit is contained in:
parent
fb324e7576
commit
6c9d1c328b
16 changed files with 54 additions and 37 deletions
|
@ -9,6 +9,8 @@ namespace Foxnouns.Backend.Services;
|
|||
|
||||
public class KeyCacheService(DatabaseContext db, IClock clock, ILogger logger)
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<KeyCacheService>();
|
||||
|
||||
public Task SetKeyAsync(string key, string value, Duration expireAfter) =>
|
||||
SetKeyAsync(key, value, clock.GetCurrentInstant() + expireAfter);
|
||||
|
||||
|
@ -40,7 +42,7 @@ public class KeyCacheService(DatabaseContext db, IClock clock, ILogger logger)
|
|||
public async Task DeleteExpiredKeysAsync(CancellationToken ct)
|
||||
{
|
||||
var count = await db.TemporaryKeys.Where(k => k.Expires < clock.GetCurrentInstant()).ExecuteDeleteAsync(ct);
|
||||
if (count != 0) logger.Information("Removed {Count} expired keys from the database", count);
|
||||
if (count != 0) _logger.Information("Removed {Count} expired keys from the database", count);
|
||||
}
|
||||
|
||||
public Task SetKeyAsync<T>(string key, T obj, Duration expiresAt) where T : class =>
|
||||
|
|
|
@ -7,21 +7,25 @@ namespace Foxnouns.Backend.Services;
|
|||
public class ObjectStorageService(ILogger logger, Config config, IMinioClient minio)
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<ObjectStorageService>();
|
||||
|
||||
|
||||
public async Task RemoveObjectAsync(string path)
|
||||
{
|
||||
logger.Debug("Deleting object at path {Path}", path);
|
||||
_logger.Debug("Deleting object at path {Path}", path);
|
||||
try
|
||||
{
|
||||
await minio.RemoveObjectAsync(new RemoveObjectArgs().WithBucket(config.Storage.Bucket).WithObject(path));
|
||||
}
|
||||
catch (InvalidObjectNameException)
|
||||
{
|
||||
// ignore non-existent objects
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PutObjectAsync(string path, Stream data, string contentType)
|
||||
{
|
||||
_logger.Debug("Putting object at path {Path} with length {Length} and content type {ContentType}", path,
|
||||
data.Length, contentType);
|
||||
|
||||
await minio.PutObjectAsync(new PutObjectArgs()
|
||||
.WithBucket(config.Storage.Bucket)
|
||||
.WithObject(path)
|
||||
|
|
|
@ -17,7 +17,7 @@ public class PeriodicTasksService(ILogger logger, IServiceProvider services) : B
|
|||
private async Task RunPeriodicTasksAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.Debug("Running periodic tasks");
|
||||
|
||||
|
||||
await using var scope = services.CreateAsyncScope();
|
||||
|
||||
var keyCacheSvc = scope.ServiceProvider.GetRequiredService<KeyCacheService>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue