0

i upgraded my .net core 3.1 api to .net 6. i use console and file sinks of serilog but my custom logs from my controller do not get to the log sinks. other logs from the application pipeline get to the file. all logs worked in version 3.1 and i have not made any changes to my program.cs which looks like

`        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(Configuration)
                .Enrich.FromLogContext()
                .CreateLogger();

            try
            {
                Log.Information("Starting web host");
                CreateWebHostBuilder(args)
                .UseIISIntegration()
                .Build()
                .Run();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "API Host terminated unexpectedly");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }


public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
           WebHost.CreateDefaultBuilder(args)
            
           .UseContentRoot(Directory.GetCurrentDirectory())
           .UseIISIntegration()
           .UseStartup<Startup>()
           .UseSerilog();`

i've checked the serilog configuration and it looks ok. i am wondering i need to change the entire program.cs to conform with .net 6 for serilog to work. i am using serilog 3.4.

this is my serilog config:

"Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
    "MinimumLevel": {
      "Default": "Information"
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "===> {Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"
        }
      },
      {
        "Name": "File",
        "Args": {
          "path": "/tmp/logs/xxxx.json",
          "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
          "rollingInterval": "Day",
          "outputTemplate": "===> {Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"
          //"retainedFileCountLimit": 10
          //"fileSizeLimitBytes": 2048
        }
      }


    ]
  },
Sola
  • 13
  • 2

0 Answers0