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.