proudmonkey / ApiBoilerPlate

A simple yet organized project template for building ASP.NET Core APIs in .NET Core 3.1
MIT License
361 stars 77 forks source link

[RFT] Modify Serilog config implementation #7

Closed judedaryl closed 4 years ago

judedaryl commented 4 years ago
  1. Added the gitignore for the .vscode folder for Visual Studio Code users
  2. Removed the implicit declaration adding a json file based on the ASPNETCORE_ENVIRONMENT value.

By default .NET Core now ports over all the appsettings.{ANY}.json files and will override the values in the main appsettings.json file based on the environment used. I haven't found any docs for this but I've confirmed this behavior myself.

appsettings.json

{
   "Nested": {
      "EnvSpecific": "Default",
      "ShouldDefault": "Default"
   }
}

appsettings.Staging.json

{
   "Nested": {
      "EnvSpecific": "Stage"
   }
}

Resulting appsettings when calling IConfiguration

{
   "Nested": {
      "EnvSpecific": "Stage",
      "ShouldDefault": "Default"
   }
}
  1. Removed the applogsettings.json that contains the specifications for Serilog
  2. Removed the config builder declaration in the Main entry point of the assembly

This is for a more graceful approach at injecting the Serilog configuration. We are already using the UseSerilog extension which exposes an Action that contains the HostingContext (AspNet hosting context) and the LoggerConfiguration (Serilog's config for the Serilog factory in Line 123).

  1. Added additional configs in launchSettings.json for a more seamless Visual Studio experience. I have one for VSCode but I added it to the .gitignore to reduce noise

Criticisms or changes please if applicable @proudmonkey!

judedaryl commented 4 years ago

Makes sense. I've added the Serilog settings in appsettings.Logs.json and added it as a config source in Program.cs.