This is probably a repeat of How to set Steeltoe Dynamic Logging works with 3rd party loggers as Serilog?. I would like to leverage Steeltoe dynamic logging configuration(Will help me to adjust the log levels dynamically without a redeployment) and wanted to make my log statements more structured. So I decided to take a look at Serilog. Here is my code
public class Program
{
/// <summary>
/// Application entry point.
/// </summary>
/// <param name="args">arguments.</param>
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostContext, config) =>
{
config.AddCloudFoundry();
})
.ConfigureLogging((context, builder) =>
{
// We need to clear providers which are added by CreateDefaultBuilder().
// Please refer https://github.com/aspnet/Logging/issues/648. Otherwise log entries will be duplicated
// since AddDynamicConsole again add console logger
builder.ClearProviders();
if (context.HostingEnvironment.IsDevelopment())
{
builder.AddDebug();
}
builder.AddDynamicConsole();
})
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate:
"[{Level:u3}] [{Properties}] {Message}{NewLine}{Exception}")
.WriteTo.Trace())
.Build();
}
But this is not working as expected. In PCF Apps manager, I am not able to see any logging provider apart from "Default". If I uncomment
UseSerilog()
they are back as well. Btw, I don't want to restrict my self to Serilog and is this possible with NLog(heard that it also supports structured logging)? Or any other thoughts to combine structured logging and dynamic logging configuration are most welcome