using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Console; using Microsoft.Extensions.Logging.Debug; using Microsoft.Extensions.Logging.EventSource; using Microsoft.Extensions.Logging.AzureAppServices; using Microsoft.Extensions.Logging.Configuration; using Microsoft.Extensions.Logging.Debug; using Microsoft.Extensions.Logging.EventSource; using Microsoft.Extensions.Logging.TraceSource; using Microsoft.Extensions.DependencyInjection; // AddDbLogger example public class Program { static void Main(string[] args) { // create ServiceCollection and add logging var serviceCollection = new ServiceCollection(); serviceCollection.AddLogging(builder => { builder.AddConsole(); builder.AddEventSourceLogger(); builder.AddAzureWebAppDiagnostics(); builder.AddTraceSource(new SourceSwitch("sourceSwitch", "Verbose")); builder.AddDbLogger(options => options.ConnectionString = "connectionString"); }); // build provider and create logger var serviceProvider = serviceCollection.BuildServiceProvider(); var logger = serviceProvider.GetServiceIn this example, we first create a ServiceCollection and add logging functionality using AddLogging. We then add several different logging providers including console, event source, Azure app diagnostics, and trace source. Finally, we use AddDbLogger to add the capability of logging data to a database. We specify the database connection string in the options object that is passed to AddDbLogger. We then build the service provider and use it to retrieve a logger instance for our program. We log an informative message using the logger instance with the DB logger. The package library used for this example is Microsoft.Extensions.Logging.>(); // log a message logger.LogInformation("Logging message with DB logger."); } }