-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathClearLogsCommand.cs
More file actions
36 lines (28 loc) · 1.12 KB
/
ClearLogsCommand.cs
File metadata and controls
36 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using CleanArchitecture.Blazor.Application.Features.Loggers.Caching;
namespace CleanArchitecture.Blazor.Application.Features.Loggers.Commands.Clear;
public class ClearLogsCommand : ICacheInvalidatorRequest<Result>
{
public string CacheKey => LogsCacheKey.GetAllCacheKey;
public IEnumerable<string>? Tags => LogsCacheKey.Tags;
}
public class ClearLogsCommandHandler : IRequestHandler<ClearLogsCommand, Result>
{
private readonly IApplicationDbContext _context;
private readonly ILogger<ClearLogsCommandHandler> _logger;
public ClearLogsCommandHandler(
IApplicationDbContext context,
ILogger<ClearLogsCommandHandler> logger
)
{
_context = context;
_logger = logger;
}
public async Task<Result> Handle(ClearLogsCommand request, CancellationToken cancellationToken)
{
await _context.Loggers.ExecuteDeleteAsync();
_logger.LogInformation("Logs have been erased");
return await Result.SuccessAsync();
}
}