Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 2.37 KB

dynamic-logging-provider.md

File metadata and controls

59 lines (42 loc) · 2.37 KB

Dynamic Logging Provider

This logging provider is a wrapper around the Microsoft Console Logging provider. This wrapper allows for querying the currently defined loggers and their levels as well as then modifying the levels dynamically at runtime.

CAUTION: External tool integration involves sending the fully-qualified logger name over HTTP. Avoid using colons in the name of a logger to prevent invalid HTTP Requests.

Usage

Before starting to use Steeltoe provider, you should know how the .NET logging service works, as it is nothing more than a wrapper around the existing Microsoft console logger.

To use the Steeltoe logging provider, you need to:

  1. Add the logging NuGet package references to your project.
  2. Configure Logging settings.
  3. Add the dynamic logging provider to the logging builder.

Add NuGet References

To use the logging provider, you need to add a reference to the Steeltoe Dynamic Logging NuGet.

The provider is found in the Steeltoe.Extensions.Logging.DynamicLogger package.

You can add the provider to your project by using the following PackageReference:

<ItemGroup>
...
    <PackageReference Include="Steeltoe.Extensions.Logging.DynamicLogger" Version="3.2.0"/>
...
</ItemGroup>

Configure Settings

As mentioned earlier, the Steeltoe Logging provider is a wrapper around the Microsoft Console logging provider. Consequently, you can configure it the same way you would the Microsoft provider. For more details on how this is done, see the section on Log Filtering.

Add the Logging Provider

To use the provider, you need to add it to the logging builder by using the AddDynamicConsole() extension method:

using Steeltoe.Extensions.Logging;
public class Program
{
    public static void Main(string[] args)
    {
        var host = WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .ConfigureLogging((builderContext, loggingBuilder) =>
            {
                // Add Steeltoe Dynamic Logging provider
                loggingBuilder.AddDynamicConsole();
            })
            .Build();

        host.Run();
    }
}