1

Currently, my Serilog implementation logs files in descending order - displays the oldest message at the top and the newest message at the bottom. I would like my implementation to log in ascending order - newest at the top and oldest at the bottom.

This is what I currently have in Program.cs:

public static void Main(string[] args)
        {
            string timestamp = DateTime.Now.ToString("[yyyy-MM-dd][HH.mm.ss tt]", CultureInfo.InvariantCulture);

            Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .Enrich.FromLogContext()
            .WriteTo.File($"C:\\Logs\\{timestamp}-log.txt",
                outputTemplate: "Time:{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
                rollingInterval: RollingInterval.Day,
                restrictedToMinimumLevel: LogEventLevel.Information
             )
            .CreateLogger();

            CreateHostBuilder(args).Build().Run();
        }

How can I achieve this?

Meeth46
  • 61
  • 4
  • 1
    as far as i know serilog does not support this. may be you can directly raise issue on [github](https://github.com/serilog/serilog-sinks-file) and serilog developers can tell if this is possible or not. – CodingMytra Sep 08 '22 at 16:58
  • 2
    Writing to the start of a file means you need to copy all the stuff in the file to the end. And that needs to be done transactionally correct in the face of potentially multiple writers. That's simply not how Files can work in any reasonable way, so no real logging solutions do that. Logging servers on the other hand, typically let you see the most recent events first, but then they are indexing things – Ruben Bartelink Sep 09 '22 at 09:45

0 Answers0