3

I am trying to configure appsettings.json so that I have multiple Serilog variables for each of our environments(Dev, UAT, Prod etc) I have the following serilog that works for dev:

    "Serilog": {
  "MinimumLevel": "Verbose",
  "Using": [
    "Serilog.Sinks.Console",
    "Serilog.Sinks.Seq"
  ],
  "WriteTo": [
    {
      "Name": "Console"
    },
    {
      "Name": "Seq",
      "Args": {
        "serverUrl": "https://seq-dev.test.com"
      },
      "Properties": {
        "Application": "Console.Sample",
        "Environment": "Local"
      }
    }
  ]
},

My current solution is to have an array of Serilog instance. I am going to be passing an arg into main specificying which environment I want and I should use that Seq instance(Example: args: Environment="d" for dev - this should pull the dev Serilog)

    "d": {
  "Serilog": {
    "MinimumLevel": "Verbose",
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.Seq"
    ],
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "https://seq-dev.test.com"
        },
        "Properties": {
          "Application": "Console.Sample",
          "Environment": "Local"
        }
      }
    ]
  }
},
"q": {
  "Serilog": {
    "MinimumLevel": "Verbose",
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.Seq"
    ],
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "https://seq-dev.test.com"
        },
        "Properties": {
          "Application": "Console.Sample",
          "Environment": "Local"
        }
      }
    ]
  }
},
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
cpage
  • 31
  • 3

1 Answers1

2

This is more of a configuration thing.

You need to specify a appsettings json for each environment

enter image description here

The one that will be used by the application is determine by this ENV variable

enter image description here

Paul Lorica
  • 703
  • 4
  • 6
  • Thank you Paul for the quick answer! This is more of a utility app and will basically ping each environment at any time based off the command line args provided. Its not like this will be hosted in a dev environment and it will only hit dev. Therefor I am not sure Environment Variables are the right solution. Is there a way to set environment variables based off command line args? Or specify which app settings.json to use via command line "dev", "prod" ect? Thanks in advanced – cpage Sep 02 '21 at 20:08
  • Is this a asp.net core app? or a console .net core app? In any case both would have a section of code that handles the reading of the appsettings.json. I would think you just set your variable logic there – Paul Lorica Sep 02 '21 at 20:41