Reputation: 389
I am using .net core 3.1 function app and implemented app insight. Error is logging good and I am able to see it in azure portal app insight but receiving below error when trying to log information.
AI (Internal): [Microsoft-ApplicationInsights-AspNetCore] ERROR: Exception in Command Processing for EventSource Microsoft-ApplicationInsights-AspNetCore : An instance of EventSource with Guid dbf4c9d9-6cb3-54e3-0a54-9d138a74b116 already exists.
How to write information logs to azure app insight. I have already tried many stackoverflow and MS suggestions. Even tried updating app insight version fron 2.17.0 to 2.19.0. Nothing worked.
local.settings.json
"values" :{
"INSTRUMENTATION_KEY": "*******************",
},
"logging": {
"logLevel": {
"default": "Information",
"Function": "Information",
"Host.Aggregator": "Trace",
"Host.Results": "Error"
}
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": false
}
}
}
}
startup.cs
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddLogging();
// Add and Configure Application Insight
builder.Services.AddApplicationInsightsTelemetry(Environment.GetEnvironmentVariable("INSTRUMENTATION_KEY"));
}
Function:
public class TestFunction
{
private readonly ILogger<TestFunction> _log;
public TestFunction(ILogger<TestFunction> log)
{
_log = log;
}
[FunctionName("TestFunction")]
public async Task Run([TimerTrigger("%RUN_SCHEDULE%")] TimerInfo myTimer)
{
_log.LogInformation("I am not working :("); //Log is not written to azure app insight
_log.LogError("Yipee I am working"); //Able to see error logs in app insgight
}
}
Upvotes: 0
Views: 1309
Reputation: 29860
The error
AI (Internal): [Microsoft-ApplicationInsights-AspNetCore] ERROR: Exception in Command Processing for EventSource Microsoft-ApplicationInsights-AspNetCore : An instance of EventSource with Guid dbf4c9d9-6cb3-54e3-0a54-9d138a74b116 already exists.
is unrelated to the fact that you cannot see the telemetry with severity level Information
.
Per default AI only logs telemetry with severity Warning
or higher. To change that you need to specify the log level of the AI category like this:
{
"Logging": {
"LogLevel": {
"default": "Information",
"Function": "Information",
"Host.Aggregator": "Trace",
"Host.Results": "Error"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
}
}
},
"ApplicationInsights": {
"InstrumentationKey": "************"
}
}
Upvotes: 0