Я использую веб-задания v3 с HostBuilder.
Как мне настроить регистратор, чтобы я мог использовать telemetryClient для отслеживания данных, которые видны на выходе консоли И видны в службе приложений Azure
эта веб-работа запущена?
Я хотел бы получить экземпляр ILogger, который регистрируется в консоли AND azure.
эта строка кода:
var logger = host.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("I log only in the console but not azure.");
НЕ отправляет свои данные в диаграммы анализа приложений Azure ...
Я НЕ хочу использовать ILogger И телеметрический клиент для записи глупостей.
var builder = new HostBuilder()
.UseEnvironment("Development")
.ConfigureWebJobs(b =>
{
// Add extensions and other WebJobs services
})
.ConfigureAppConfiguration(b =>
{
// Add configuration sources
})
.ConfigureLogging((context, b) =>
{
// Add Logging Providers
b.AddConsole();
// If this key exists in any config, use it to enable App Insights
string appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]; // taken from the appservice environmentvariable
appInsightsKey = "xxxxxxxx";
if (!string.IsNullOrEmpty(appInsightsKey))
{
// This uses the options callback to explicitly set the instrumentation key.
b.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey);
}
})
.UseConsoleLifetime();
var host = builder.Build();
// my code like telemetryClient.TrackTrace("show this text in console output AND azure app service where this webjob belongs to")
using (host)
{
host.Run();
}