fix: better logging
- verbose logging for log channel resolving logic - don't LOG TOKENS TO THE CONSOLE OR SEQ - actually log verbose logs to seq - report open db connections to prometheus
This commit is contained in:
parent
7749c9d9e2
commit
5157105c35
7 changed files with 109 additions and 50 deletions
|
|
@ -20,14 +20,9 @@ using Npgsql;
|
|||
|
||||
namespace Catalogger.Backend.Database;
|
||||
|
||||
public class DatabaseConnection(Guid id, ILogger logger, NpgsqlConnection inner)
|
||||
: DbConnection,
|
||||
IDisposable
|
||||
public class DatabaseConnection(NpgsqlConnection inner) : DbConnection, IDisposable
|
||||
{
|
||||
public Guid ConnectionId => id;
|
||||
public NpgsqlConnection Inner => inner;
|
||||
private readonly ILogger _logger = logger.ForContext<DatabaseConnection>();
|
||||
private readonly DateTimeOffset _openTime = DateTimeOffset.UtcNow;
|
||||
|
||||
private bool _hasClosed;
|
||||
|
||||
|
|
@ -43,8 +38,6 @@ public class DatabaseConnection(Guid id, ILogger logger, NpgsqlConnection inner)
|
|||
}
|
||||
|
||||
DatabasePool.DecrementConnections();
|
||||
var openFor = DateTimeOffset.UtcNow - _openTime;
|
||||
_logger.Verbose("Closing connection {ConnId}, open for {OpenFor}", ConnectionId, openFor);
|
||||
_hasClosed = true;
|
||||
await inner.CloseAsync();
|
||||
}
|
||||
|
|
@ -52,11 +45,7 @@ public class DatabaseConnection(Guid id, ILogger logger, NpgsqlConnection inner)
|
|||
protected override async ValueTask<DbTransaction> BeginDbTransactionAsync(
|
||||
IsolationLevel isolationLevel,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
_logger.Verbose("Beginning transaction on connection {ConnId}", ConnectionId);
|
||||
return await inner.BeginTransactionAsync(isolationLevel, cancellationToken);
|
||||
}
|
||||
) => await inner.BeginTransactionAsync(isolationLevel, cancellationToken);
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue