Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log txn POST params and hide EF core logs #407

Merged
merged 2 commits into from
Jan 19, 2024
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
25 changes: 20 additions & 5 deletions Sloth.Api/Controllers/v2/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Serilog;
using Sloth.Api.Attributes;
using Sloth.Api.Errors;
using Sloth.Api.Models.v2;
Expand Down Expand Up @@ -185,8 +186,6 @@ public async Task<IList<Transaction>> GetByMetadata(string key, string value)
return transactions;
}

// TODO: just for testing, remove later

/// <summary>
/// Validate Financial Segment String
/// </summary>
Expand All @@ -199,9 +198,6 @@ public async Task<bool> ValidateFinancialSegmentString(string id)
return await _aggieEnterpriseService.IsAccountValid(id);
}


// TODO: update to AE

/// <summary>
/// Create a Transaction with a list of Transfers
/// </summary>
Expand All @@ -212,6 +208,8 @@ public async Task<bool> ValidateFinancialSegmentString(string id)
[ProducesResponseType(typeof(BadRequestObjectResult), 400)]
public async Task<IActionResult> Post([FromBody] CreateTransactionViewModel transaction)
{
LogTransactionCreating(transaction);

var teamId = GetTeamId();

if (!ModelState.IsValid)
Expand Down Expand Up @@ -364,6 +362,23 @@ await _context.Database.CreateExecutionStrategy().ExecuteAsync(async () =>
return new JsonResult(transactionToCreate);
}

private void LogTransactionCreating(CreateTransactionViewModel transaction)
{
var txn = new
{
transaction.KfsTrackingNumber,
transaction.ProcessorTrackingNumber,
transaction.MerchantTrackingNumber,
transaction.MerchantTrackingUrl,
transaction.Source,
transaction.SourceType,
Transfers = transaction.Transfers.Select(t => new { t.Amount, t.FinancialSegmentString, t.Description, t.Direction }).ToArray(),
Metadata = transaction.Metadata.Select(m => new { m.Name, m.Value }).ToArray(),
};

Log.Information("Transaction Creation Starting: {@Transaction}", txn);
}

private string GetTeamId()
{
return User.FindFirst(ClaimTypes.PrimaryGroupSid)?.Value;
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Api/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Jobs.Core/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Web/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down