Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging to database in ASP.NET Core MVC 6

In my old MVC5 project all log informations was saved on a sql server database through log4net. I would like keep logger structure of ASP.NET 5 without using any more the log4net. Is it possibile saving the logs on a database table? What kind of code should I use?

like image 385
Sauron Avatar asked Dec 20 '15 09:12

Sauron


People also ask

Does NLog support .NET 6?

The NLog. Web. AspNetCore-package supports the platforms: For ASP.NET Core 6, .


2 Answers

You can implement ILoggerFactory and ILogger however you like including, for example, logging to a database.

Here's an example of an ILogger implementation that uses EntityFramework 6 to save logs to a database.

like image 62
Stafford Williams Avatar answered Sep 17 '22 02:09

Stafford Williams


I've created new project that is a bit more flexible and available for Entity Framework Core. Here is the GitHub project site:

https://github.com/msmolka/ZNetCS.AspNetCore.Logging.EntityFrameworkCore

like image 24
Marcin Avatar answered Sep 20 '22 02:09

Marcin