-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup Azure AppConfiguration hence enable logging to SEQ
- Loading branch information
1 parent
c49b629
commit ee147d8
Showing
7 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
server/Tingle.Dependabot/AzureAppConfigurationStartupFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Tingle.Dependabot; | ||
|
||
internal class AzureAppConfigurationStartupFilter : IStartupFilter | ||
{ | ||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) | ||
{ | ||
return builder => | ||
{ | ||
var configuration = builder is WebApplication webApp | ||
? webApp.Configuration | ||
: builder.ApplicationServices.GetRequiredService<IConfiguration>(); | ||
|
||
/* | ||
* If the endpoint is not null, then AppConfiguration services were added. | ||
* This means we can add the middleware to the pipeline. | ||
* Otherwise it would throw an exception. | ||
*/ | ||
var endpoint = configuration.GetValue<Uri?>("AzureAppConfig:Endpoint"); | ||
if (endpoint is not null) | ||
{ | ||
builder.UseAzureAppConfiguration(); | ||
} | ||
|
||
next(builder); | ||
}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
server/Tingle.Dependabot/Extensions/ConfigurationManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Azure.Identity; | ||
|
||
namespace Microsoft.Extensions.Configuration; | ||
|
||
/// <summary>Extensions for <see cref="ConfigurationManager"/>.</summary> | ||
public static class ConfigurationManagerExtensions | ||
{ | ||
/// <summary> | ||
/// Adds standard Azure AppConfiguration provider and services. | ||
/// </summary> | ||
/// <param name="manager">The <see cref="ConfigurationManager"/> to be configured.</param> | ||
/// <param name="environment">The <see cref="IHostEnvironment"/> to use.</param> | ||
/// <returns></returns> | ||
public static ConfigurationManager AddStandardAzureAppConfiguration(this ConfigurationManager manager, IHostEnvironment environment) | ||
{ | ||
var section = manager.GetSection("AzureAppConfig"); | ||
var endpoint = section.GetValue<Uri?>("Endpoint"); | ||
var label = section.GetValue<string?>("Label") ?? environment.EnvironmentName; | ||
if (endpoint is not null) | ||
{ | ||
var cacheExpiration = section.GetValue<TimeSpan?>("CacheExpiration") ?? TimeSpan.FromHours(1); | ||
var cacheExpirationInterval = section.GetValue<TimeSpan?>("CacheExpirationInterval") ?? TimeSpan.FromMinutes(30); | ||
manager.AddAzureAppConfiguration(options => | ||
{ | ||
options.Connect(endpoint: endpoint, credential: new DefaultAzureCredential()) | ||
.Select("*", label) | ||
.ConfigureRefresh(o => | ||
{ | ||
o.Register("Refresh", label, refreshAll: true) // key to use to trigger refresh | ||
.SetCacheExpiration(cacheExpiration); | ||
}) | ||
.UseFeatureFlags(o => | ||
{ | ||
o.Label = label; | ||
o.CacheExpirationInterval = cacheExpirationInterval; | ||
}); | ||
}); | ||
} | ||
|
||
return manager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters