Skip to content

Commit

Permalink
Merge pull request #16 from microsoft/update-appsettings-load
Browse files Browse the repository at this point in the history
Update appsettings load
  • Loading branch information
bradarm authored Aug 2, 2024
2 parents bf68a74 + baf164c commit e4ea89b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddJsonFile("/workspaces/hostsvc-logging-config/appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("/workspaces/hostsvc-logging/src/appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("/workspaces/hostsvc-logging/src/appsettings.{env:DOTNET_ENVIRONMENT}.json", optional: true, reloadOnChange: true)
.Build();
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);

builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Services/LogWriterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
string jsonString = JsonSerializer.Serialize(logMessage, jsonOptions);

// Append the serialized log message to the log file
await File.AppendAllTextAsync(logFileName, jsonString, stoppingToken);
await File.AppendAllLinesAsync(logFileName, new string[] { jsonString }, stoppingToken);

// Call post-write plugins
_pluginLoader.CallPlugins<MessageFormats.Common.LogMessage?, Plugins.PluginBase, string>(
Expand Down
11 changes: 8 additions & 3 deletions test/debugClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);

builder.Configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings.{env:DOTNET_ENVIRONMENT}.json", optional: true, reloadOnChange: true);
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);

builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down
9 changes: 8 additions & 1 deletion test/integrationTests/TestSharedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ public TestSharedContext() {
if (_grpcHost != null) return;

var builder = WebApplication.CreateBuilder();
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);

builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down

0 comments on commit e4ea89b

Please sign in to comment.