Skip to content

Commit

Permalink
feat: introdued log event ids
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaVetnic committed Oct 13, 2023
1 parent f80bd88 commit 704f8d0
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public void Complete()
{
foreach (var databaseId in _databaseIds)
{
_logger.LogError("no blob found for token id: '{databaseId}'", databaseId);
_logger.NoBlobForTokenId(databaseId);
}

foreach (var blobId in _blobIds)
{
_logger.LogError("no database entry found for blob id: '{blobId}'", blobId);
_logger.NoDatabaseEntryForBlobId(blobId);
}
}

Expand All @@ -39,3 +39,30 @@ public void ReportOrphanedDatabaseId(TokenId id)
_databaseIds.Add(id);
}
}

file static class LoggerExtensions
{
private static readonly Action<ILogger, TokenId, Exception> NO_BLOB_FOR_TOKEN_ID =
LoggerMessage.Define<TokenId>(
LogLevel.Error,
new EventId(826083, "Tokens.SanityCheck.NoBlobForTokenId"),
"No blob found for token id: '{tokenId}'."
);

private static readonly Action<ILogger, string, Exception> NO_DATABASE_ENTRY_FOR_BLOB_ID =
LoggerMessage.Define<string>(
LogLevel.Error,
new EventId(271286, "Tokens.SanityCheck.NoDatabaseEntryForBlobId"),
"No database entry found for blob id: '{blobId}'."
);

public static void NoBlobForTokenId(this ILogger logger, TokenId tokenId)
{
NO_BLOB_FOR_TOKEN_ID(logger, tokenId, default!);
}

public static void NoDatabaseEntryForBlobId(this ILogger logger, string blobId)
{
NO_DATABASE_ENTRY_FOR_BLOB_ID(logger, blobId, default!);
}
}

0 comments on commit 704f8d0

Please sign in to comment.