I am trying to get my function to log to app insights but I seem to have tried several things and to no avail. I am using V4 functions and running it locally using
var config = TelemetryConfiguration.Active;
var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.ApplicationInsights(config, TelemetryConverter.Traces)
.CreateLogger();
Please note I am aware TelemetryConfiguration.Active
is not recommended but I am trying to get something to work for now.
The host is setup as:
var host = new HostBuilder()
.UseSerilog((context, configuration) =>
{
configuration.Enrich.FromLogContext();
})
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices((hostContext, services) =>
{
services.AddLogging(logging => logging.AddSerilog(logger, true));
})
.Build();
host.Run();
My appsettings has instrumentation key set
{
"ApplicationInsights": {
"InstrumentationKey": "59d7227e-",
"EnableAdaptiveSampling": false,
"EnablePerformanceCounterCollectionModule": false
}
}
My function I attempt to use ILogger to do the following
_logger.LogInformation("HELLO WORLD");
_logger.LogWarning("HELLO WORLD WARNING");
However I don’t see these log lines in app insights. What am I doing wrong here?