C
C#7mo ago
Pounika

ef core audit log interceptor?

i want to log all changes in my webapi project by creating a "auditLogs" table and storing table names, column names, prev and current values of the changed property etc. i've used interceptors for the first time to override the savingChangesAsync method by inheriting SaveChangesInterceptor. however no matter what i tried, i couldnt figure out 1) how to access the user id using the httpContext, or 2) how to access the dbContext to insert my logs into the database. can someone help?
No description
3 Replies
Tvde1
Tvde17mo ago
Get the context accessor by making a constructor that has it as a param And your DbContext is named db You might need to cast it to the actual context you're using. I don't know if there's a better way to do that with generics or so
Pounika
PounikaOP7mo ago
im confused as to where to call that constructor, this is where i add the interceptor to my project but context accessor isnt here...?
No description
Pounika
PounikaOP7mo ago
using db.Set<User>() actually worked! i thought i had to somehow access my own dbRepository... thanks a lot
Want results from more Discord servers?
Add your server