Reputation: 1777
I feel like I have tried it all to get log messages shown in the Azure portal.
I have installed the relevant NuGet packages in my project:
I've enabled logging in the Azure Portal.
I have added the following to my appsettings.json
:
"AzureLogging": {
"FileName": "azure-diagnostics-",
"FileSizeLimit": 50024,
"RetainedFileCountLimit": 5
}
And the following setup code in Startup
to be sure it had added one of them.
services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
});
The only thing I am able to get from my logs is the following:
Upvotes: 1
Views: 3192
Reputation: 30035
In your Startup.cs -> Configure method, you should add the following lines of code:
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
Here is the code of Configure method in my Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
//add the following 2 lines of code.
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
After publish to azure -> enable Application logging(Filesystem), then in Log Stream, I can see the output of logs(I set log level to verbose in my test):
Upvotes: 2