Reputation: 154
I've a sample AzureIotEdgeApp with one IotEdgeModule (C#). In that one, I've a single file (program.cs) and I'm writing some logging information to application insights. But it never writes. I also have a launchSettings.json where I've an environment variable APPINSIGHTS_INSTRUMENTATIONKEY.
I've the same code in a net core sample console app (2.2 and 3.1) and it just works fine.
What am I missing?
static void Main(string[] args)
{
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
var serviceProvider = serviceCollection.BuildServiceProvider();
var logger = serviceProvider.GetService<ILogger<Program>>();
for (var i=1; i<=2; i++)
{
logger.LogInformation("Testing an information message");
logger.LogError("Testing an error message");
}
Console.ReadKey();
}
private static void ConfigureServices(IServiceCollection services)
{
Log.Logger = new LoggerConfiguration() // Serilog
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.ApplicationInsights(TelemetryConfiguration.Active, TelemetryConverter.Traces)
.CreateLogger();
services.AddLogging(configure => configure.AddSerilog(Log.Logger)).AddScoped<TelemetryClient>();
}
I've the following packages added.
Microsoft.ApplicationInsights - 2.12.0 Microsoft.Extensions.DependencyInjection - 3.1.0 Serilog - 2.0 Serilog.Extensions.Logging - 3.0.1 Serilog.Sinks.ApplicationInsights - 3.0.4
Upvotes: 1
Views: 228
Reputation: 154
The application insights key should be added in deployment.json file, not in launchSettings.json as normal net core console application.
Upvotes: 1