{"id":19976654,"url":"https://github.com/erossini/auditnetwebapi","last_synced_at":"2025-05-04T03:30:30.684Z","repository":{"id":63981822,"uuid":"325392848","full_name":"erossini/AuditNetWebApi","owner":"erossini","description":"Implementation of Audit.NET with ASP.NET Core3.1 and Entity Framework","archived":false,"fork":false,"pushed_at":"2021-01-04T14:35:26.000Z","size":33,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T02:43:09.569Z","etag":null,"topics":["audit","csharp","csharp-code","sql-server","swagger","webapi-core"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erossini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":"AuditConfiguration.cs","citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-29T21:42:34.000Z","updated_at":"2023-04-12T17:53:40.000Z","dependencies_parsed_at":"2023-01-14T17:16:06.788Z","dependency_job_id":null,"html_url":"https://github.com/erossini/AuditNetWebApi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erossini%2FAuditNetWebApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erossini%2FAuditNetWebApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erossini%2FAuditNetWebApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erossini%2FAuditNetWebApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erossini","download_url":"https://codeload.github.com/erossini/AuditNetWebApi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252283518,"owners_count":21723485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audit","csharp","csharp-code","sql-server","swagger","webapi-core"],"created_at":"2024-11-13T03:24:53.275Z","updated_at":"2025-05-04T03:30:30.060Z","avatar_url":"https://github.com/erossini.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Implementation of an audit strategy with C# and Audit.NET\n\nHow to implement an efficient _audit_ system with [C#](https://www.puresourcecode.com/category/dotnet/csharp/) and [Entity Framework Core](https://www.puresourcecode.com/tag/entity-framework-core/)? \n\n## Structure of the audit tables\n![Audit in action](https://www.puresourcecode.com/wp-content/uploads/2021/01/audit-entity-framework-core.png)\n\nI have talked about Entity Framework in my previous posts:\n\n*   [Creating A Model For An Existing Database](https://www.puresourcecode.com/dotnet/net-core/creating-a-model-for-an-existing-database-in-entity-framework-core/)\n*   [Entity Framework Core And Calling A Stored Procedure](https://www.puresourcecode.com/dotnet/net-core/entity-framework-core-and-calling-a-stored-procedure/)\n*   [Transactions With Entity Framework Core](https://www.puresourcecode.com/dotnet/csharp/transactions-with-entity-framework-core/)\n*   [Database Connection Resiliency In Entity Framework Core](https://www.puresourcecode.com/dotnet/net-core/database-connection-resiliency-in-entity-framework-core/)\n*   [Database Connection Resiliency In Entity Framework Core: Update](https://www.puresourcecode.com/dotnet/net-core/database-connection-resiliency-in-entity-framework-core-update/)\n\nOften, during my implementation, there is a common request: track all changes in the database and where and who is changing a record.\n\nA way to implement an audit is to override the `SubmitChanges` function in your data context. I created a post about it a long time ago; it was 2014\\. The post has title [Log record changes in SQL server in an audit table](https://www.puresourcecode.com/news/apps/log-record-changes-in-sql-server-in-an-audit-table/) and I was using Entity Framework.\n\nSo, I googled a bit and I found a very nice NuGet package that can help us to implement what we need. [Audit.NET](https://github.com/thepirat000/Audit.NET) is the package and it is pretty complete. Although the documentation is good, I was struggle to understand how to use it in my project. For this reason, I want to give you all my thoughts and the final solution. So, you can use it.\n\nFor the full explanation of this code, read [Audit with Entity Framework Core](https://www.puresourcecode.com/dotnet/net-core/audit-with-entity-framework-core/)\n\n## API samples\n\nDescription | Command\n------------ | -------------- \n**Get all records** | ```curl -X GET http://localhost:50732/api/values -H \"content-type: application/json\"```\n**Get record** | ```curl -X GET http://localhost:50732/api/values/1 -H \"content-type: application/json\"```\n**Insert record** | ```curl -X POST http://localhost:50732/api/values -H \"content-type: application/json\" -d '\"Some description\"'```\n**Update record** | ```curl -X PUT http://localhost:50732/api/values/1 -H \"content-type: application/json\" -d '\"New description\"'```\n**Delete record** | ```curl -X DELETE http://localhost:50732/api/values/1 -H \"content-type: application/json\"```\n**Delete multiple records** | ```curl -X DELETE http://localhost:50732/api/values/delete -H \"content-type: application/json\" -d '\"2,3,4\"'```\n**Get all records** | ```curl -X GET http://localhost:50732/api/contacts -H \"content-type: application/json\"```\n**Get record** | ```curl -X GET http://localhost:50732/api/contacts/1 -H \"content-type: application/json\"```\n**Insert record** | ```curl -X POST http://localhost:50732/api/contacts -H \"content-type: application/json\" -d '\"Some description\"'```\n**Update record** | ```curl -X PUT http://localhost:50732/api/contacts/1 -H \"content-type: application/json\" -d '\"New description\"'```\n**Delete record** | ```curl -X DELETE http://localhost:50732/api/contacts/1 -H \"content-type: application/json\"```\n**Delete multiple records** | ```curl -X DELETE http://localhost:50732/api/contacts/delete -H \"content-type: application/json\" -d '\"2,3,4\"'```\n\nIf you have any question, please use my [forum](https://www.puresourcecode.com/forum/) and visit my [blog](https://www.puresourcecode.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferossini%2Fauditnetwebapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferossini%2Fauditnetwebapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferossini%2Fauditnetwebapi/lists"}