-
Notifications
You must be signed in to change notification settings - Fork 129
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
Is it possible to set this Configuration key/value in Azure App Settings (or Environmental Vars?) #102
Comments
Hi @PureKrome 👋 Yes, it's possible, although unfortunately it's not an optimal process right now; I believe given your config above, the variable name will be something like: |
I have similar need for AzureBlobStorage. Details here: chriswill/serilog-sinks-azureblobstorage#47 I ended up with something similar to what is described here and then extended is some. Basically I build the configuration twice. After first build of configuration I AddInMemoryCollection to overwrite the secrets/connectionstrings and use the second config to configure the logger. Most importantly, I keep the paths ("Serilog:WriteTo:1:Args:connectionString") in appsettings.json and used that to know which keys to add in AddInMemoryCollection. var configurationBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false, true)
.AddEnvironmentVariables();
IConfiguration configuration = configurationBuilder.Build();
var pathsToInjectStorageConnectionString = configuration.GetSection("PathsToInjectStorageConnectionString").GetChildren().Select(section => section.Value);
if (pathsToInjectStorageConnectionString.Any())
{
var storageConnectionString = new Dmp.Timelines.Backup(configuration["DmpAppStorageAccountName"], configuration["DmpAppStorageAccountKey"]).StorageAccount.ToString(true);
configurationBuilder.AddInMemoryCollection(pathsToInjectStorageConnectionString.Select(path => new KeyValuePair<string, string>(path, storageConnectionString)));
configuration = configurationBuilder.Build();
}
var loggerConfiguration = new LoggerConfiguration()
.ReadFrom.Configuration(configuration); |
@lucasmaj why build the config 2x. I didn't have to .... |
I guess in your situation the Serilog:WriteTo:1:Args:token was already an Environmental variable? In my case the storage account name and key were two separate environment variables which needed to be combined into a connections string at run time. |
For a reference: |
Anyone get a working example of this? |
it's something like this: given the configuration file snippet:
in your env-vars (like Azure App Service) you would have
|
Hi 👋
Give this serilog configuration k/v's .. can this be set in Azure's App Settings or in Environmental Variables (which is what Azure does anyways):
Trying to set that Logentries
token
value.It's the array, that's confusing me...
e.g.
appsettings.production.json
The text was updated successfully, but these errors were encountered: