0

The log file for my site is being cached somewhere. The same log file is being written again and again after multiple restarts.

How do I clear the cache and force the log file to be generated each time the server starts?

Edit: by "generated" I mean new log entries written to disk either by being appended to the existing log file or a new file being created.

Edit 2: I am trying to troubleshoot a startup problem on my site. I am actually deploying new builds to the site and I am getting cached log files across builds.

I use Serilog. I doubt Serilog could cache across process restarts but I am including my log configuration anyway.

Steps to reproduce:

  • Stop the service
  • FTP the log file to local machine.
  • Delete the log file from the Azure server
  • Start the service
  • Repeat

Note in step 3 above I am physically deleting the the entire file from disk.

The files shown below were generated about a half hour apart over multiple restarts:

File 1

2021-01-08 15:53:21.849 +00:00 [INF] Vy
2021-01-08 15:53:22.064 +00:00 [INF] En
2021-01-08 15:53:29.847 +00:00 [INF] Az
2021-01-08 15:53:31.862 +00:00 [INF] No
2021-01-08 15:53:31.864 +00:00 [FTL] Ho
2021-01-08 15:53:32.304 +00:00 [INF] Ap
2021-01-08 15:53:32.311 +00:00 [INF] Ho
2021-01-08 15:53:32.332 +00:00 [INF] Co
2021-01-08 15:53:32.402 +00:00 [INF] Re
2021-01-08 15:53:32.485 +00:00 [INF] Re

File 2

2021-01-08 15:53:21.849 +00:00 [INF] Vy
2021-01-08 15:53:22.064 +00:00 [INF] En
2021-01-08 15:53:29.847 +00:00 [INF] Az
2021-01-08 15:53:31.862 +00:00 [INF] No
2021-01-08 15:53:31.864 +00:00 [FTL] Ho
2021-01-08 15:53:32.304 +00:00 [INF] Ap
2021-01-08 15:53:32.311 +00:00 [INF] Ho
2021-01-08 15:53:32.332 +00:00 [INF] Co
2021-01-08 15:53:32.402 +00:00 [INF] Re
2021-01-08 15:53:32.485 +00:00 [INF] Re

Logging config:

public class Program
{
    public static void Main(string[] args)
    {
        string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        string logRoot = null;

        if (env == "Development")
            logRoot = "c:\\serilog\\myDomain.Web\\log";
        else
            logRoot = "..\\..\\serilog\\myDomain.Web\\log";   // Create logs in D:\home\serilog

        // Note UseSerilog() in CreateHostBuilder below.
        Log.Logger = new LoggerConfiguration()
           .WriteTo.File(logRoot, rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
           .CreateLogger();

        try
        {
            Log.Information("myDomain.Web - Program.Main started.");
            Log.Information("Environment is: {env}", env);
            CreateHostBuilder(args).Build().Run();
        }
        catch (Exception ex)
        {
            Log.Error(ex.ToString());
        }
        finally
        {
            Log.CloseAndFlush();
        }
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseSerilog()
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });
}
  • You have to p Service - You can also inspect the log files from the browser at https://.scm.azurewebsites.net/api/logs/docker. – AjayKumar Jan 11 '21 at 12:56
  • You can have Application Logging (Filesystem) or Application Logging (Blob). Kindly see the location of the logs: For Windows apps, the ZIP file contains the contents of the **D:\Home\LogFiles** directory>>in the App Service file system -/LogFiles/Application/ https://learn.microsoft.com/azure/app-service/configure-language-dotnetcore?pivots=platform-linux#access-diagnostic-logs An alternative to using the "Diagnose and solve problems" blade is to examine the Application Event Log file directly using Kudu. – AjayKumar Jan 11 '21 at 13:10
  • And, with the new Azure Monitor integration - https://learn.microsoft.com/azure/app-service/troubleshoot-diagnostic-logs#send-logs-to-azure-monitor-preview – AjayKumar Jan 11 '21 at 13:10
  • @AjayKumar Thank you for your comments however I am not asking how to view the logs. I am asking how to clear the cache. –  Jan 11 '21 at 14:50
  • @Sam try deploying to a staging slot and see if the issue is reproducible there. – MrBrooks Jan 12 '21 at 02:35
  • @MrBrooks I will have to figure out how to create one - why do you think the result will be any different with a staging slot? –  Jan 12 '21 at 02:49
  • A staging slot has is a completely separate web app that will have no ability to pull a "cached" version of the logfile. If you go to the web app in the Azure Portal -> Deployment slots -> Add a slot then deploy the same code and see if the log file is generated. If the file is created its wouldn't be a cache issue. https://learn.microsoft.com/en-us/azure/app-service/deploy-staging-slots – MrBrooks Jan 12 '21 at 02:58
  • @MrBrooks on first deployment I expect I would see a new file. However if I deploy to that slot multiple times should I expect to see a newly generated log file or new log entries appended to existing file? That is the problem I'm having. I am troubleshooting startup errors - when I deploy new code I just see the log file from my last deployment. –  Jan 12 '21 at 03:22
  • Does the same behavior occur locally as well? Based on your code the only difference in the logging would be the log file location correct? – MrBrooks Jan 12 '21 at 14:55
  • @MrBrooks Works fine locally. I'm sure there are many differences in machine config - not sure how Azure machines are configured or how Azure tweaks logging for streaming, etc. –  Jan 12 '21 at 15:24
  • @Sam, https://learn.microsoft.com/en-us/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-5.0#aspnet-core-module-debug-log-azure-app-service (debugging the log) Just to highlight, Asp.net core have web.config on App Service. If you look at your web.config, it probably has stdoutLogEnabled="false". If you set that to true, then anything that is written to standard output will be written to a file. And the stdoutLogFile determines where it goes, which by default is under d:\home\logfiles. – AjayKumar Jan 12 '21 at 19:05
  • Yes, you could create your own logging system that writes to the file system of the app, and your file is automatically streamed and downloaded ( as in your case). All you have to do is write application code that creates files in the d:\home\logfiles folder (not C: drive – due to App Service Sandbox restrictions) https://stackoverflow.com/a/35026372/8194837 The Portal diagnostic blades (Diagnose and solve problems) can be used narrow-down/isolate start-up (the main the issue that you highlighted/ will follow-up to sort the log file caching) – AjayKumar Jan 12 '21 at 19:08
  • @AjayKumar-MSFT Thank you again for your comments. stdoutLogEnabled has no bearing on the question I am asking. I have removed / added back my entire web.config to try to resolve this. Note the question I am asking is not how to redirect the log file. I am asking how to reset the cache. Again, the (only) question I am asking is how to reset the cache. –  Jan 12 '21 at 21:16
  • Is this in proc or out of proc? Either way though whenever you deploy the process the main w3wp.exe is restarted killing any child process including the dotnet core process if its out of proc. I'm not familiar with how serilog works but unless it caches the results in a different process or file I'm not sure how the same output would continue to show up. Do you have a webjob or another process that's running in parallel in the application? You can navigate to https://appname.scm.azurewebsites.net/processexplorer to see all the running processes. – MrBrooks Jan 14 '21 at 03:41
  • @Sam, Just checking if the suggestions provided by MrBrooks helps. The application logs is typically not cached on App Service (through restart). Just to highlight, with Local Cache, your logs and data folders do look a little different. However, the structure of your subfolders remains the same, except that the subfolders are nestled under a subfolder with the format "unique VM identifier" + time stamp. In this case, typically to flush the local cache logs, we just stop and restart the app.This action clears the old cache. – AjayKumar Jan 18 '21 at 19:26
  • Apologies for any confusion. @Sam, To investigate this issue further - could you share the WebApp name indirectly (share partial WebApp and subscription ID)? Kindly see this doc - https://github.com/projectkudu/kudu/wiki/Reporting-your-site-name-without-posting-it-publicly Note: Please do not share any PII info on the public forum. – AjayKumar Jan 18 '21 at 19:28
  • @AjayKumar-MSFT Have not been able to test MrBrooks suggestions, have been traveling due to family illness. Here is partial client ID of site: 9ea79dd6...53f003 please let me know if you need more info. –  Jan 19 '21 at 00:38
  • @Sam, So sorry to hear about the illness in your family, hope things improve soon. Along with the partial subscription ID, I also need the WebApp name. For a quick and specialized assistance, please send an email with subject line “Attn:Ajay” to AzCommunity[at]Microsoft[dot]com with your Azure subscription ID, and your WebApp name, I will follow-up with you. – AjayKumar Jan 20 '21 at 14:23

0 Answers0