Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
970 views
in Technique[技术] by (71.8m points)

azure - Log file is cached across service restarts

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

        // 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>();
        });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...