Reputation: 967
I have created an ASP.NET Core 3.1 application. The application is deployed to a Azure App Service. In the project I make use of logging, but the problem is that I can't view the logs on Azure via Log Stream.
Below is how I configured it:
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var logger = host.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("The application has started");
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) => {
logging.AddConfiguration(context.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddAzureWebAppDiagnostics();
})
.ConfigureServices(serviceCollection => serviceCollection
.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
})
.Configure<AzureBlobLoggerOptions>(options =>
{
options.BlobName = "log.txt";
}))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
This should work right? When I go to Log Stream I should be able to see all the logs? If so, why don't I see any of the logs I created?
I don't what is happening in my code and I need the logs.
Upvotes: 3
Views: 1822
Reputation: 973
In Azure App Service, your code looks good , but just ensure that you have enabled Application Logging.
Please find out more info regarding the same here -
Enable Application logging
Enable Web server logging
If you save to the filesystem
Enable Detailed Error messages
Enable Failed request tracing
For more info : please look at this doc reference.
Upvotes: 3