No video

Audit Trail Implementation in ASP.NET Core Web API

  Рет қаралды 1,887

Code Maze

Code Maze

Күн бұрын

►► Master Web API development Best Practices: bit.ly/3TnqoFQ
►► Build great web apps in Blazor WebAssembly: bit.ly/437g87T
►► Support us on Patreon and get the source code: / codemaze
Hi everyone. My name is Marinko Spasojevic and in this video, I will show you the proper way of implementing an audit trail in ASP.NET Core Web API.
An audit trail refers to the record of all activities that the users perform in an application. We use it to identify who accessed the application, what changes were made, etc.
An audit trail typically includes the information about:
The author of the change
The date and time of the change
The type of change
The changed data
We can store audit trail data in databases, files, storage services, etc. The most common way is to store this kind of data in the application database and we are going to learn how to do that.
FOLLOW US ON SOCIAL MEDIA!
►► / marinko-spasojevic
►► / codemazeblog
►► / codemazeblog

Пікірлер: 25
@CodeMaze
@CodeMaze Ай бұрын
Thank you all for watching and for your support. ►► If you want to master Web API development using best practices, check out our Web API book: bit.ly/3x75ZMM ►► Also, to build great full-stack apps with Blazor, check out our course: bit.ly/3Pw3Y33
@duongchinhngu2407
@duongchinhngu2407 Ай бұрын
Great tutorial! thank you!
@CodeMaze
@CodeMaze Ай бұрын
You're very welcome! Thanks for watching.
@FearGod123
@FearGod123 Ай бұрын
Great video. Thank you very much
@CodeMaze
@CodeMaze Ай бұрын
You are welcome! Thanks for watching it.
@10Totti
@10Totti Ай бұрын
Great tutorial, I've been using this technique for a long time.
@CodeMaze
@CodeMaze Ай бұрын
Thank you. Yeah, it is a great approach, and easy to implement.
@cissemy
@cissemy Ай бұрын
Thanks
@CodeMaze
@CodeMaze Ай бұрын
You are most welcome.
@seldomseen_78
@seldomseen_78 Ай бұрын
Great stuff, as usual. We have a nearly identical implementation except for the part where, instead of the changes column, we save entity JSON, so if something needs to be compared, simply compare the JSON objects to see what changed. Also, you can retrieve a deleted object.
@CodeMaze
@CodeMaze Ай бұрын
Thanks for the kind words. Yeah, that sounds great as well. This can serve as a base idea for everyone and then, we all can modify it per our needs.
@progressnwimuelekara2167
@progressnwimuelekara2167 Ай бұрын
Really great stuff, man. Thank you very much!
@CodeMaze
@CodeMaze Ай бұрын
You are most welcome. Thank you for watching.
@Miraziz-dotnet
@Miraziz-dotnet Ай бұрын
Great tutorial as always.
@CodeMaze
@CodeMaze Ай бұрын
Thanks a lot. Glad you like it.
@andresbeltran5779
@andresbeltran5779 Ай бұрын
Good afternoon, always happy to learn new things with your videos. Based on your experience, should some migration or backup be implemented from time to time to prevent this table from becoming huge? I understand that everything is relative but to at least have an idea
@CodeMaze
@CodeMaze Ай бұрын
Hi. Thank you for watching the videos, it is great if you can learn something new from those. Regarding your question, definitely. Depending on the ferquency of the logs the ferquency of backups should be decided, but again, I am pretty sure, as we all log a lot, the tables will become large pretty soon, so some sort of backup should be advised. Now it is up to the team to decide wether they want to do the entire db backup or just this table, but again, it should be done.
@GustavoAdolfoRodríguezBeteta
@GustavoAdolfoRodríguezBeteta Ай бұрын
How can I use this approach with a service layer or with unit of work?
@CodeMaze
@CodeMaze Ай бұрын
You don't have to worry about that. You are overriding the SaveChanges method that you have to call if you are using EF Core to make the changes to the database. You can use any architecture or any pattern you want, this still doesn't affect the logic from the video.
@GustavoAdolfoRodríguezBeteta
@GustavoAdolfoRodríguezBeteta 15 күн бұрын
@@CodeMaze thanks
@venky76v
@venky76v Ай бұрын
Hi, Do you have the source code on GitHub? Please, if you can share it??
@10Totti
@10Totti Ай бұрын
Patreon.
@CodeMaze
@CodeMaze Ай бұрын
Hi, no we don't have a public GitHub repo for the source code. It is part of the patreon membership with some other privileges.
@marklnz
@marklnz Ай бұрын
So this is a bit of an "old school" way to do this. There are better options, in my opinion. The biggest issue I have with this approach is that it only supports add/update/delete actions. Most real world audit requirements involve logging read access also. Further, you're using the HTTPClient directly in the data access layer - it would definitely be a more "pure" approach to avoid that and pull the user information from the ThreadPrincipal, for example, instead.
@CodeMaze
@CodeMaze Ай бұрын
Hi. First of all thanks for watching the video and for the comment. I definitely didn't invent this approach :) I've been using it for years now, so we certainly can't say it is the newest approach out there, but it works great and people will use it for sure. Regarding the second thing - yes this approach can't be used for GET requests and to be honest I never use Audit logs for GET requests only for the requests that make changes to my database, I simply use regular logs if I need any info about the GET flow in my app. I am not using HtppClient, I am just accessing the HttpContext here, and yes, you can definitely move that logic to any service and then inject that service here, I just didn't want to go into that in this video and make the video any longer. For me using the HttpContext.User property is the standard way of getting users' information so I just used it here, but I am sure everyone can adapt the solution to their needs.
Implementing API Gateway With Ocelot in ASP.NET Core
13:26
Code Maze
Рет қаралды 2,2 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 158 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
Underwater Challenge 😱
00:37
Topper Guild
Рет қаралды 42 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 3,6 МЛН
Don’t Use UUIDs/GUIDs in Databases. Use this Instead
10:36
Nick Chapsas
Рет қаралды 44 М.
Forgot Password Implementation in an Identity Project
4:24
Serilog 🚀 Logging in .NET 7 Made Simple & Fun
16:23
Patrick God
Рет қаралды 44 М.
How to Implement API Versioning for Minimal APIs | ASP.NET Core 8
18:11
Milan Jovanović
Рет қаралды 14 М.
Swagger is Going Away in .NET 9!
10:48
Nick Chapsas
Рет қаралды 93 М.
How .NET Aspire will save .NET (and its not about "the cloud")
8:54
The Best Way To Add Audit Tables to Your Database
8:48
Database Star
Рет қаралды 6 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН