Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Application/Common/Interfaces/IApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.


using CleanArchitecture.Blazor.Domain.Entities;
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace CleanArchitecture.Blazor.Application.Common.Interfaces;

public interface IApplicationDbContext
{
DbSet<Logger> Loggers { get; set; }
DbSet<SystemLog> SystemLogs { get; set; }
DbSet<AuditTrail> AuditTrails { get; set; }
DbSet<Document> Documents { get; set; }
DbSet<PicklistSet> PicklistSets { get; set; }
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions src/Application/Features/Loggers/DTOs/LogTimeLineDto.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/Application/Features/Loggers/Mappers/LogMapper.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CleanArchitecture.Blazor.Application.Features.Loggers.Caching;
namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.Caching;

public static class LogsCacheKey
public static class SystemLogsCacheKey
{
public const string GetAllCacheKey = "all-logs";
public static string GetChartDataCacheKey(string parameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.SystemLogs.Caching;

namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.Commands.Clear;

public class ClearSystemLogsCommand : ICacheInvalidatorRequest<Result>
{
public string CacheKey => SystemLogsCacheKey.GetAllCacheKey;
public IEnumerable<string>? Tags => SystemLogsCacheKey.Tags;
}

public class ClearSystemLogsCommandHandler : IRequestHandler<ClearSystemLogsCommand, Result>

{
private readonly IApplicationDbContext _context;
private readonly ILogger<ClearSystemLogsCommandHandler> _logger;

public ClearSystemLogsCommandHandler(
IApplicationDbContext context,
ILogger<ClearSystemLogsCommandHandler> logger
)
{
_context = context;
_logger = logger;
}

public async Task<Result> Handle(ClearSystemLogsCommand request, CancellationToken cancellationToken)
{
await _context.SystemLogs.ExecuteDeleteAsync();
_logger.LogInformation("Logs have been erased");
return await Result.SuccessAsync();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CleanArchitecture.Blazor.Application.Features.Loggers.DTOs;
namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.DTOs;

public class LogDto
public class SystemLogDto
{
[Description("Id")] public int Id { get; set; }

Expand All @@ -13,11 +13,11 @@ public class LogDto

[Description("Level")] public string Level { get; set; } = default!;

[Description("Timestamp")] public DateTime TimeStamp { get; set; } = DateTime.UtcNow;
[Description("Datetime")] public DateTime TimeStamp { get; set; } = DateTime.UtcNow;

[Description("Exception")] public string? Exception { get; set; }

[Description("Username")] public string? UserName { get; set; }
[Description("User name")] public string? UserName { get; set; }

[Description("Client IP")] public string? ClientIP { get; set; }

Expand Down
10 changes: 10 additions & 0 deletions src/Application/Features/SystemLogs/DTOs/SystemLogTimeLineDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.DTOs;

public class SystemLogTimeLineDto
{
public DateTime dt { get; set; }
public int total { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CleanArchitecture.Blazor.Application.Features.SystemLogs.DTOs;

namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.Mappers;
[Mapper]
public static partial class SystemLogMapper
{
public static partial SystemLogDto ToDto(SystemLog logger);
public static partial IQueryable<SystemLogDto> ProjectTo(this IQueryable<SystemLog> q);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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.SystemLogs.Caching;
using CleanArchitecture.Blazor.Application.Features.SystemLogs.DTOs;

namespace CleanArchitecture.Blazor.Application.Features.SystemLogs.Queries.ChatData;

public class SystemLogsTimeLineChatDataQuery : ICacheableRequest<List<SystemLogTimeLineDto>>
{
public DateTime LastDateTime { get; set; } = DateTime.Now.AddDays(-60);
public string CacheKey => SystemLogsCacheKey.GetChartDataCacheKey(LastDateTime.ToString());
public IEnumerable<string>? Tags => SystemLogsCacheKey.Tags;
}

public class SystemLogsChatDataQueryHandler : IRequestHandler<SystemLogsTimeLineChatDataQuery, List<SystemLogTimeLineDto>>

{
private readonly IApplicationDbContext _context;
private readonly IStringLocalizer<SystemLogsChatDataQueryHandler> _localizer;

public SystemLogsChatDataQueryHandler(
IApplicationDbContext context,
IStringLocalizer<SystemLogsChatDataQueryHandler> localizer
)
{
_context = context;
_localizer = localizer;
}

public async Task<List<SystemLogTimeLineDto>> Handle(SystemLogsTimeLineChatDataQuery request,
CancellationToken cancellationToken)
{
var data = await _context.SystemLogs.Where(x => x.TimeStamp >= request.LastDateTime)
.GroupBy(x => new { x.TimeStamp.Date })
.Select(x => new { x.Key.Date, Total = x.Count() })
.OrderBy(x => x.Date)
.ToListAsync(cancellationToken);

List<SystemLogTimeLineDto> result = new();
DateTime end = new(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
var start = request.LastDateTime.Date;

while (start <= end)
{
var item = data.FirstOrDefault(x => x.Date == start.Date);
result.Add(item != null
? new SystemLogTimeLineDto { dt = item.Date, total = item.Total }
: new SystemLogTimeLineDto { dt = start, total = 0 });

start = start.AddDays(1);
}

return result.OrderBy(x => x.dt).ToList();
}
}
Loading
Loading