Kiksen
Kiksen

Reputation: 1777

Microsoft.Extensions.Logging.AzureAppServices not showing up in Azure log streams

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:

Microsoft.ApplicationInsights.AspNetCore

I've enabled logging in the Azure Portal.

enter image description here

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:

enter image description here

Upvotes: 1

Views: 3192

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

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):

enter image description here

Upvotes: 2

Related Questions