How to log to database using the built-in Asp.Net core logging (Microsoft.Extensions.Logging)?

ca9163d9 picture ca9163d9 · Sep 13, 2016 · Viewed 9.5k times · Source

I have the following code to set up logging to database using NLog. I use an Alpha version of NLog.Extension.Logging. Is it possible to let the built-in log framework log to database so I don't need to use NLog?

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();
    loggerFactory.AddNLog();
    env.ConfigureNLog("nlog.config");

    app.UseApplicationInsightsRequestTelemetry();

    app.UseApplicationInsightsExceptionTelemetry();

    app.UseMvc();
}

Answer

Saša Ćetković picture Saša Ćetković · Jul 26, 2017

There is a NuGet package for that (DISCLAIMER: I made it): https://www.nuget.org/packages/DLogger.Extensions.Logging

The GitHub repository: https://github.com/SasaCetkovic/DLogger.Extensions.Logging