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{ Â Â Â Â Â ...