Logging CRUD operations ASPNET Core, AspNetUsers, AspNetUserRoles

murtaza gandhi 81 Reputation points
2021-02-12T12:47:23.217+00:00

Hi,

I want to log and create UI where logs of CRUD operations could be viewed.

It can be which user updated what fields or columns

The Users are ASPNETUSERS

Can we get such logging ?

I am using EF ASP.Net Core MVC

Thanks,
Regards.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,280 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 49,781 Reputation points
    2021-02-12T15:04:09.857+00:00

    In your code that you want to log use the existing ILogger interface defined by .NET Core. Log whatever you want.

    To log the data to a custom store such as a database table create a custom logging provider as discussed here. The provider should write any logs to your custom database. Then hook up the provider at app startup like you are already likely doing. There is the ConfigureLogging extension method off the host builder that your app is already using that allows you to customize the logging. Add your provider to the logging at this point and it'll be called correctly. Note that your log provider will get called for all logs so you'll need to decide if you only want certain log messages or all of them.

    Alternatively if you don't want to build your own provider use one of the third party providers such as Log4Net or NLog. They generally have pre-defined code to allow writing to a database but you may have less control over the structure of that data.

    0 comments No comments

0 additional answers

Sort by: Most helpful