1

I'm using serilog for my .net core web api2.1 project. everything is working as expected in local but if i publish the code and if i create two endpoints which are pointing to same published code then serilog is creating two different logs for two endpoints but i would like to maintain in one single log file.could you please help me with this? this is my program.cs file

public class Program
    {
        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder().AddJsonFile("appsettings.json",false,true).Build();
            Log.Logger = new LoggerConfiguration()
               .Enrich.FromLogContext()
               .ReadFrom.Configuration(config)
               .CreateLogger();

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

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .UseSerilog() 
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }

and appsettings.json as below.

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          "path": "Logs/applog_.log",
          "outputTemplate": "{Timestamp:o} [{Level:u3}] ({SourceContext}) {Message}{NewLine}{Exception}",
          "retainedFileCountLimit": 7,
          "fileSizeLimitBytes": 50000000,
          "rollOnFileSizeLimit": true
        }
      }
    ],
    "Enrich": [ "FromLogContext"],
    "Properties": {
      "Application": "AspNetCoreSerilogDemo"
    }
  },
  "AllowedHosts": "*"
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Surya
  • 103
  • 1
  • 7
  • Where are the two files ending up. Can you define 'two endpoint' - is that two completely separate programs / processes? What sort of environment are you running in? – Ruben Bartelink Jun 08 '21 at 07:39
  • endpoints are **http://beta.claimvalidatorversion3.0.com/ and http://beta.claimvalidatorv3:492/ ** in my local IIS server and two end points are mapping to same folder **E:\Publish\WithNetCore3.0** . but if run two end points then two separate files are creating inside Logs folder. i have running in my local IIS environment and testing environment(AWS). – Surya Jun 08 '21 at 07:47

0 Answers0