Aspnetcore.docs: How to configure flags for Debug and EventSource logger

Created on 16 Jun 2019  ยท  4Comments  ยท  Source: dotnet/AspNetCore.Docs

The page describes what the example configuration does, however, it is not clear how to configure other logging targets (e.g. EventSource or Debug). So more examples or a in-depth explanation would be awesome.


Document Details

โš  Do not edit this section. It is required for docs.microsoft.com โžŸ GitHub issue linking.

P2 Source - Docs.ms

Most helpful comment

We often list/explain options (usually mirrored content from the API docs), but we'd be hard pressed to doc all of the options for every framework feature. Also, there's generally ๐Ÿƒ a lot of engineering churn ๐Ÿƒ with options.

One way to handle this is to link to the options in the API browser. Today, it's often a reader-unfriendly process to get to them. For example, take the Console Provider ...

  • In the reference source: The Console provider section links to the NuGet package. The package links to the source repo. Then ... src > Logging > Logging.Console > src > ConsoleLoggerOptions.cs to see them.
  • In the API docs: The reader is probably ๐Ÿ˜ต trying to guess the namespace to search.

In the Console provider case, we could link https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.console.consoleloggeroptions. The reader can select their version. We wouldn't need to list/explain every one. Engineering can modify them each release with reduced doc churn.

All 4 comments

The first code sample shows how to do that:

public static void Main(string[] args)
{
    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) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
            logging.AddDebug();
            logging.AddEventSourceLogger();
        })
        .UseStartup<Startup>()
        .Build();

    webHost.Run();
}

Thanks for your quick feedback. Maybe, I did not explain myself clearly. The examples show how to hook up configuration that is located elsewhere (appsettings.json or environment variables) and also show an example of the appsettings configuration, but it does not show which flags can be set in those configuration files and which are available in general. This was something which I expected from the Configuration chapter but which was not available there.

We often list/explain options (usually mirrored content from the API docs), but we'd be hard pressed to doc all of the options for every framework feature. Also, there's generally ๐Ÿƒ a lot of engineering churn ๐Ÿƒ with options.

One way to handle this is to link to the options in the API browser. Today, it's often a reader-unfriendly process to get to them. For example, take the Console Provider ...

  • In the reference source: The Console provider section links to the NuGet package. The package links to the source repo. Then ... src > Logging > Logging.Console > src > ConsoleLoggerOptions.cs to see them.
  • In the API docs: The reader is probably ๐Ÿ˜ต trying to guess the namespace to search.

In the Console provider case, we could link https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.console.consoleloggeroptions. The reader can select their version. We wouldn't need to list/explain every one. Engineering can modify them each release with reduced doc churn.

@lefe For the two that you asked about IIRC, I don't think there are options to configure (but you should look to make sure). For the rest of the providers, I'll link their options API docs.

Was this page helpful?
0 / 5 - 0 ratings