I am using webjobs v3 with HostBuilder.
How do I have to configure the logger that I can use a telemetryClient to tracktrace data which is visible in the console output AND visible in the azure app service this webjob is running on?
I would like to get a ILogger instance which logs to console AND azure.
this line of code:
var logger = host.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("I log only in the console but not azure.");
DOES not send its data to azure application insights charts...
I do NOT want to use the ILogger AND the telemetryclient to log stuff that would be stupid.
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();
}