Tracking Raw Sql Queries in Audit.EntityFramework.Core
See original GitHub issueHello,
I just implemented Audit.NET and I am using the Audit.EntityFramework.Core library to track entity changes.
I noticed that any calls to SaveChangesAsync
is tracked just as stated. The issue is any query executed using DbContext.Database.ExecuteSqlRawAsync()
is not tracked.
Is there a way to track these kind of changes?
Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Executing Raw SQL Queries using Entity Framework Core
Entity Framework Core provides mechanisms for executing raw SQL queries including stored procedures directly against the database.
Read more >Audit trail with Entity Framework Core - sql server
If you plan to store the audit logs in the same database as the audited entities, you can use the EntityFrameworkDataProvider . Use...
Read more >Audit Trail Implementation in ASP.NET Core with Entity ...
Well, it's a handy technique to track changes that are done by your logged-in users. Ever wondered who had updated the value of...
Read more >Overview of logging and interception - EF Core
Entity Framework Core (EF Core) contains several mechanisms for generating logs, responding to events, and obtaining diagnostics.
Read more >How To Track Entity Changes With EF Core | Audit Logging
However, with EF Core there is an easy way to implement entity change tracking as ... How To Apply Global Filters With EF...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A new command interceptor was provided that logs raw SQL queries, for EF Core 3.0 and EF Core 5.0 starting on version 18.1.5
More information on the readme here
So you could attach the command interceptor with:
For EF Core 5, I think one option is to use a
DbCommandInterceptor
that intercepts theExecuteSqlRaw
calls, but I’m afraid it will also intercept any other commands issued by EF internally.Check this: https://docs.microsoft.com/en-us/ef/core/logging-events-diagnostics/
For example:
Note you should also implement the Async version of the methods:
NonQueryExecutedAsync
andCommandFailedAsync
.Then you can add the interceptor when creating your DbContext, for example: