Skip to content

- IdentityServer4, Admin, Admin.Api, STS.Identity, added support for environment-specific configuration files #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2020

Conversation

ViRuSTriNiTy
Copy link
Contributor

… in logging setup and CreateHostBuilder(), see issue #549

…environment-specific configuration files in logging setup and CreateHostBuilder(), refs issue skoruba#549
…8 BOM in modified files to clean-up PR, refs issue skoruba#549
@ViRuSTriNiTy ViRuSTriNiTy marked this pull request as ready for review March 25, 2020 10:05
@@ -38,7 +38,9 @@ private static IConfiguration GetConfiguration(string[] args)
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("serilog.json", optional: true, reloadOnChange: true);
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this line ? I think apps already works with appsettings{environemnt}.json by default.

Copy link
Contributor Author

@ViRuSTriNiTy ViRuSTriNiTy Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho yes, this line is necessary as there is no "automagic" going on here, see #549 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this line. If anyone wants a custom serilog configuration. The configuration should be mounted into the application.

Define in your release pipeline to mount the serilog.json from the outside to the inside. The proposed line will not work with docker and kubernetes

Copy link
Contributor Author

@ViRuSTriNiTy ViRuSTriNiTy Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this line. If anyone wants a custom serilog configuration. The configuration should be mounted into the application.

Define in your release pipeline to mount the serilog.json from the outside to the inside. The proposed line will not work with docker and kubernetes

Thanks for your feedback but i don't understand your instructions. What does "mounted into the application" actually mean and what "release pipeline"? Do you mean i should copy serilog.Development.json to serilog.json before releasing the application? And why is the proposed solution not working with docker and kubernetes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you look at the docker compose below
https://github.com/skoruba/IdentityServer4.Admin/blob/master/docker-compose.yml#L35

This give the flexibility for anyone to define serilog.json as they want and mount it from the host machine to the container

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it is not necessary but if you want I'd say if you still want to do it. do it in your fork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want only "necessary" changes not improvements, that's sad as my approach also allows config transformations via SlowCheetah, all effort in vain. Closing the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not the owner of the repo. I just gave a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The owner can very well decide to approve your pr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -61,7 +61,9 @@ private static IConfiguration GetConfiguration(string[] args)
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("serilog.json", optional: true, reloadOnChange: true);
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this line ? I think apps already works with appsettings{environemnt}.json by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b0
Copy link
Contributor

b0 commented Mar 25, 2020

At least how I am reading this: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1#default-configuration

appsettings.json and appsettings.{environment}.json are "magicaly" provided by default.

Best regards

@ViRuSTriNiTy
Copy link
Contributor Author

ViRuSTriNiTy commented Mar 25, 2020

@bo Yes i read this section too but i think its a bit misleading. I've checked the .NET Core sources and as i mentioned in the related issue the appsettings.{environment}.json is added by the DefaultBuilder, see https://github.com/dotnet/aspnetcore/blob/master/src/DefaultBuilder/src/WebHost.cs#L170. The issue here is that the logging configuration is created without the DefaultBuilder hence you need to do it manually.

Edit

I've double checked this again via digging in the sources and by testing it myself with a simple breakpoint, see:

image

In the screenshot you can see that only appsettings.json and serilog.json is loaded via the JSONConfigurationProvider which is added by AddJsonFile(). The additional EnvironmentVariablesConfigurationProvider just provides values from environment variables not from an environment based configuration file like appsettings.{environment}.json as you can see in the implementation details, see https://github.com/dotnet/extensions/blob/master/src/Configuration/Config.EnvironmentVariables/src/EnvironmentVariablesConfigurationProvider.cs.

Hope this helps to understand the issue.

@b0
Copy link
Contributor

b0 commented Mar 25, 2020

Hi @ViRuSTriNiTy ,

indeed, logging configuration is created differently and those lines are needed.

Great work. 👍

Thank you

@ViRuSTriNiTy
Copy link
Contributor Author

@b0 Thanks for reviewing. How to remove the merge block? Is @skoruba needed to resolve this?

@ViRuSTriNiTy
Copy link
Contributor Author

@skoruba Please unblock the PR when everything is ok.

@ViRuSTriNiTy
Copy link
Contributor Author

PR closed as a result of #551 (comment)

@skoruba
Copy link
Owner

skoruba commented Apr 14, 2020

@ViRuSTriNiTy - please, reopen this PR. I want to use it.
Thanks.

@ViRuSTriNiTy
Copy link
Contributor Author

@skoruba Reopened as requested

@ViRuSTriNiTy ViRuSTriNiTy reopened this Apr 14, 2020
@skoruba skoruba merged commit f92c0dd into skoruba:dev Apr 18, 2020
@skoruba
Copy link
Owner

skoruba commented Apr 18, 2020

Thanks 👍🏼

@skoruba skoruba mentioned this pull request Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants