Reputation: 155
I was trying to use the new Steeltoe Serilog Dynamic Logger https://steeltoe.io/docs/steeltoe-logging/#2-0-serilog-dynamic-logger in my .net core 2.2 application. I have used 2.3.0 version of Steeltoe.Extensions.Logging.SerilogDynamicLogger package. In my program.cs, I have the below code
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddCloudFoundry();
configApp.AddConfigServer();
})
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.WriteTo.Trace())
.ConfigureLogging((builderContext, loggingBuilder) =>
{
loggingBuilder.ClearProviders();
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection("Logging"));
// Add Serilog Dynamic Logger
loggingBuilder.AddSerilogDynamicConsole();
});
In the above block, first of all I dont know why
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection("Logging"));
is required because it is meant for configuring Microsoft ILogger and Serilog does not recommend such setting. Anyways, I have both in my appsettings.json
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "Trace",
"Args": {
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"Enrich": [ "FromLogContext" ]
},
After deploying to PCF, upon clicking Configure Logging Levels, I could see only 1/1 under Filter Loggers, also upon changing Default logger, log levels are not getting controlled. I am using PCF 2.4. Any thoughts on, why it is not working will be helpful.
Upvotes: 1
Views: 744
Reputation: 456
I tested the sample at https://github.com/SteeltoeOSS/Samples/tree/master/Management/src/AspDotNetCore/CloudFoundry with 2.3.0 (it is currently at 2.3.0-rc2 which is identical). It is working for me with CF 2.6. Can you try to deploy the sample in your environment and make sure the Logging endpoint looks like this:
in your cli, run cf logs <sample app name> | grep Test
. Now adjusting the Cloudfoundry.Controllers logging level, visit the home page. You should see a difference in the verbosity of the logs. Hopefully with this you can compare and see where the app/configuration is different.
➜ CloudFoundry git:(2.x) ✗ cf logs actuator | grep Test
2019-08-28T12:51:17.67-0400 [APP/PROC/WEB/0] OUT Test Critical message
2019-08-28T12:51:17.67-0400 [APP/PROC/WEB/0] OUT Test Error message
2019-08-28T12:51:17.67-0400 [APP/PROC/WEB/0] OUT Test Warning message
2019-08-28T12:51:17.67-0400 [APP/PROC/WEB/0] OUT Test Informational message
2019-08-28T12:51:17.67-0400 [APP/PROC/WEB/0] OUT Test Debug message
----- after adjusting ------
2019-08-28T12:52:16.29-0400 [APP/PROC/WEB/0] OUT Test Critical message
Upvotes: 0