简体   繁体   中英

Why I do not see logs in app service even after configuring required settings in Azure?

I have below two statements in my Web App, built using NET Core

System.Diagnostics.Trace.TraceError("header:" + certHeader);

_logger.LogInformation("Certificate with thumbprint");

I have published it to Azure App Service and here is my settings

在此处输入图片说明

Still Application folder is empty when I try to see it using kudu scm

在此处输入图片说明

I have even tried to use view streaming log option from visual studio. It did not print any log :(

在此处输入图片说明

Here is web.config

  <?xml version="1.0" encoding="utf-8"?>
  <configuration>
  <system.webServer>        
      <handlers>
          <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
      </handlers>
      <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="true" startupTimeLimit="3600"/>
  </system.webServer>

So where exactly I can see my logs?

I believe if response status is 200 OK, Trace may not be logging? Just a guess

In a asp.net core web app, we use the ILogger for the logging. More details are here .

Your settings in the azure portal is ok, just add some code in your project, sample as below:

In the Startup.cs -> Configure method, the method looks like below(Use ILoggerFactory here):

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
    {
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

       //add the following two lines of code
       logger.AddConsole();
       logger.AddDebug();

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

Then in the controller.cs:

      public class HomeController : Controller
        {
            private readonly ILogger _logger;
            public HomeController(ILoggerFactory loggerFactory)
            {
                _logger = loggerFactory.CreateLogger<HomeController>();
            }

            public IActionResult Index()
            {
                return View();
            }

            public IActionResult About()
            {
                _logger.LogInformation("ILogger --- this is from contact page!!!! info");
            _logger.LogError("ILogger --- this is from contact page xxxx error");                

            return View();
            }

           //other code
    }

You can also change the log level in appsettings.json file in your project, the default level is warning.

After publish to azure, the logs logged by ILogger can be seen in Log Stream. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM