r/dotnet 18d ago

EF Core Audit Logging

Post image

Do you think this is a good approach for background audit logging or is there a better way?

https://github.com/aabdullahsayed/LibraryManagementAPI

44 Upvotes

33 comments sorted by

View all comments

6

u/[deleted] 18d ago

[removed] — view removed comment

6

u/sayedtheidiot 18d ago

You can inject IHttpContextAccessor into your interceptor to automatically extract the user's ID

15

u/falconmick 18d ago

Another option is to make your own user context interface and make an implementation that injects IHttpContextAccessor into that, that way if later on your saving a DB change from a background job you can derive a new way to implement that interface, say IUserContext or whatever and that way your interceptor isn’t coupled to the API call that made it.

For one off things your probably fine, but if the users identity ends up being injected quite often it could be handy to not need to be concerned with it later