Open Closed

How To Add EventSourceLoggerProvider To Web Host #9440


0
carlo.benitez created

We need to add the EventSourceLogger to our app service. How do we do that in Program.cs file when there is no method AddEventSourceLogger when I tried to call ConfigureLogging? Here is the sample code from Microsoft docs

var webHost = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", 
                      optional: true, reloadOnChange: true);
            config.AddEnvironmentVariables();
        })
        .ConfigureLogging((hostingContext, logging) =>
        {
            // Requires `using Microsoft.Extensions.Logging;`
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
            logging.AddDebug();
            logging.AddEventSourceLogger();
        })
        .UseStartup<Startup>()
        .Build();


2 Answer(s)
  • 0
    maliming created
    Support Team

    hi

    I copy your code and it works.

  • 0
    carlo.benitez created

    Yes, just need to add the dependency to the project and import. Thanks!