Fixing insufficient logging of DB transactions
Basic DB transactions such as creating, reading, and deleting records are essential to have audit trails, especially when an error occurs as a DB function is performed.
In this recipe, we will fix the insufficient logging of a failed DB transaction, when a related exception is thrown.
How to do it…
Let's take a look at the steps for this recipe:
- From the starting exercise folder, launch VS Code by typing the following command:
code .
- Open
Pages\Backups\Edit.cshtml.cs
and notice a lack of DB operation logging in theOnPostAsync
method:public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid){ return Page(); } _context.Attach(Backup).State = EntityState.Modified; try{ ...