Skip to content

Commit

Permalink
Merge pull request #73 from RobinTTY/feature/Add-serilog-and-seq-sink
Browse files Browse the repository at this point in the history
Integrate Serilog and Seq. Resolves #72
  • Loading branch information
RobinTTY authored Sep 28, 2024
2 parents 79f9631 + 3e03211 commit dcfd2bb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
var builder = WebApplication.CreateBuilder(args);
var appConfig = AppConfigurationManager.AppConfiguration;

// HTTP Setup
// Configure logging
builder.Host.UseSerilog((context, loggerConfig) =>
{
loggerConfig.ReadFrom.Configuration(context.Configuration);
});

// HTTP setup
builder.Services
.AddHttpClient()
.AddCors(options =>
Expand All @@ -29,7 +35,7 @@
options.AddDefaultPolicy(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
});

// DB Setup
// DB setup
// TODO: The filepath shouldn't be hardcoded
builder.Services.AddDbContextPool<ApplicationDbContext>(options =>
options.UseSqlite("Data Source=../RobinTTY.PersonalFinanceDashboard.Infrastructure/application.db"));
Expand Down Expand Up @@ -63,7 +69,7 @@
// - Since the authentication/retrieval logic will differ from provider to provider, it will be difficult
// to abstract this logic away into one unified interface, so maybe I will need to refine/scrap this idea later...

// HotChocolate GraphQL Setup
// HotChocolate GraphQL setup
builder.Services
// TODO: Configure cost analyzer at some point (enforces maximum query costs)
.AddGraphQLServer(disableCostAnalyzer: true)
Expand All @@ -82,6 +88,7 @@
db.Database.Migrate();
}

app.UseSerilogRequestLogging();
app.UseCors();
app.MapGraphQL();
app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
</PackageReference>
<PackageReference Include="RobinTTY.NordigenApiClient" Version="10.1.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0-dev-00310" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.Seq"
],
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
"Override": {
"Microsoft.AspNetCore": "Warning"
}
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using RobinTTY.PersonalFinanceDashboard.Core.Models;
using RobinTTY.PersonalFinanceDashboard.Infrastructure.Mappers;
using RobinTTY.PersonalFinanceDashboard.Infrastructure.Services;
Expand All @@ -12,6 +13,7 @@ namespace RobinTTY.PersonalFinanceDashboard.Infrastructure.Repositories;
/// </summary>
public class BankingInstitutionRepository
{
private readonly ILogger _logger;
private readonly ApplicationDbContext _dbContext;
private readonly GoCardlessDataProvider _dataProvider;
private readonly BankingInstitutionMapper _bankingInstitutionMapper;
Expand All @@ -20,14 +22,19 @@ public class BankingInstitutionRepository
/// <summary>
/// Creates a new instance of <see cref="BankingInstitutionRepository"/>.
/// </summary>
/// <param name="logger">Logger used for monitoring purposes.</param>
/// <param name="dbContext">The <see cref="ApplicationDbContext"/> to use for data retrieval.</param>
/// <param name="dataProvider">The data provider to use for data retrieval.</param>
/// <param name="bankingInstitutionMapper">The mapper used to map ef entities to the domain model.</param>
/// <param name="dataRetrievalMetadataService">TODO</param>
public BankingInstitutionRepository(ApplicationDbContext dbContext, GoCardlessDataProvider dataProvider,
public BankingInstitutionRepository(
ILogger<BankingInstitutionRepository> logger,
ApplicationDbContext dbContext,
GoCardlessDataProvider dataProvider,
BankingInstitutionMapper bankingInstitutionMapper,
ThirdPartyDataRetrievalMetadataService dataRetrievalMetadataService)
{
_logger = logger;
_dbContext = dbContext;
_dataProvider = dataProvider;
_bankingInstitutionMapper = bankingInstitutionMapper;
Expand Down Expand Up @@ -72,7 +79,7 @@ public async Task<IEnumerable<BankingInstitution>> GetBankingInstitutions(string

return bankingInstitutionModels;
}

/// <summary>
/// TODO
/// </summary>
Expand Down Expand Up @@ -110,9 +117,10 @@ private async Task RefreshBankingInstitutionsIfStale()
await DeleteBankingInstitutions();
await AddBankingInstitutions(response.Result);
await _dataRetrievalMetadataService.ResetDataExpiry(ThirdPartyDataType.BankingInstitutions);

// TODO: Replace with logger
Console.WriteLine("Banking institutions have been refreshed.");

_logger.LogInformation(
"Refreshed stale banking institution data. {updateRecords} records were updated.",
response.Result.Count());
}
else
{
Expand Down

0 comments on commit dcfd2bb

Please sign in to comment.