Are upgrading from ASP.NET Core 2.1 to ASP.NET Core 2.2 and following the official documentation guide.
Got a problem with writing the new logging configuration in Startup.cs. Specifically problems on how to handle the AzureWebAppDiagnostics.
The old configuration consisted of the following configuration:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
loggerFactory.AddApplicationInsights(app.ApplicationServices);
loggerFactory.AddAzureWebAppDiagnostics(
new AzureAppServicesDiagnosticsSettings
{
OutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} [{Level}] {RequestId}-{SourceContext}: {Message}{NewLine}{Exception}"
}
);
}
Both the AddAzureWebAppDiagnostics and the AzureAppServicesDiganosticsSettings is marked as obsolete. The later suggests to use AzureBlobLoggerOptions instead. The guide states that the logging config should be moved to something like this:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddLogging(builder => builder
.AddConsole()
.AddAzureWebAppDiagnostics());
...
}
However I have no clue on how to properly add the configuration to the ILoggingBuildler AND as an extra bonus, the AzureBlobLoggerOptions does no allow for a custom OutputTemplate. The AddApplicationInsights is also missing from the ILoggingBuilder.
Any suggestions on how to get this working like it used to be?
The custom OutputTemplate required a dependency on Serilog, which was removed for 2.2, so it's not in the file or blob options classes.
For 2.2 it's recommended to configure logging in Program.cs rather than Startup.cs; here's an example using AddAzureWebAppDiagnostics and the options classes:
This requires the NuGet package
Microsoft.Extensions.Logging.AzureAppServices
and the following using statements: