Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ When deployed on Azure logs aree available to stream. To enable:
* navigate to your application in https://portal.azure.com
* turn Application Logging (Filesystem) to On
* set the Level to Information or Verbose
* navigate to Log Stream

You can also view the log stream using Azure CLI

Expand Down
29 changes: 23 additions & 6 deletions StpFoodBlazor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging.AzureAppServices;
using StpFoodBlazor.Components;
Expand All @@ -12,18 +13,34 @@
if (builder.Environment.IsProduction())
{
// In production, use managed identity to access Key Vault
var keyVaultEndpoint = new Uri($"https://feastival.vault.azure.net/");
builder.Configuration.AddAzureKeyVault(
keyVaultEndpoint,
new DefaultAzureCredential());
var keyVaultUrl = new Uri("https://feastival.vault.azure.net/");
var credential = new DefaultAzureCredential();
var secretClient = new SecretClient(keyVaultUrl, credential);

builder.Logging.AddApplicationInsights(
try
{
KeyVaultSecret secret = await secretClient.GetSecretAsync("AppInsightsConnectionString");
string connectionString = secret.Value;

builder.Logging.AddApplicationInsights(
configureTelemetryConfiguration: (config) =>
config.ConnectionString = builder.Configuration["AppInsights"],
config.ConnectionString = connectionString,
configureApplicationInsightsLoggerOptions: (options) => {
options.IncludeScopes = true;
options.TrackExceptionsAsExceptionTelemetry = true;
});
}
catch (Exception ex)
{
// Log the exception, but don't expose sensitive details
builder.Logging.AddConsole();
var logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger("Program");
logger.LogError(ex, "Failed to retrieve Application Insights connection string from Key Vault");
throw;
}



}
else
{
Expand Down
5 changes: 1 addition & 4 deletions StpFoodBlazor/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,5 @@
}

},
"AllowedHosts": "*",
"ConnectionStrings": {
"AppInsights": "InstrumentationKey=6eff6f01-7644-4b22-b2a0-9a39ac569f2b;IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/;ApplicationId=d9b8a7fa-0af8-4a86-8f90-f787d897cc3b"
}
"AllowedHosts": "*"
}
Loading