Log the exception's message to Application Insights
See original GitHub issueI’m using C# Azure Functions. All exceptions are/shall be logged to our Application Insights. We monitor those logs in the AI by another tool.
I’ve created a very simple function:
[FunctionName(nameof(Text_ExceptionLogging))]
public FunctionResult Text_ExceptionLogging([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestMessage request, ExecutionContext context)
{
var a = SettingsManager.GetValue("-invalid-");
return true;
}
SettingsManager.GetValue
will throw an exception saying this value is not configured through the Azure Portal. When running the function and I’m connected to the output (eg. viewing the local console or the Log stream portal), I can see that message:
2021-11-26T00:00:00.110 [Error] Executed ‘Text_ExceptionLogging’ (Failed, Id=00000000-0000-0000-0000-000000000000, Duration=1ms)Configuration key -invalid- not found […]
But it’s not fully logged to the Application Insights:
column | value |
---|---|
timestamp [UTC] | 2021-11-26T00:00:00.311Z |
message | Executed ‘Text_ExceptionLogging’ (Failed, Id=00000000-0000-0000-0000-000000000000, Duration=1ms) |
severityLevel | 3 |
cloud_RoleName | MyApp |
operation_Name | Text_ExceptionLogging |
If the exception message is not logged, I can’t see / filter for it. I’ve already created a wrapper method some time ago, that catches all exceptions, logs its message and stack trace in separated actions using the built-in logger (which writes to the Application Insights), so I’m able to see additional information. The problem is that this wrapper method was not used here. Sure, I can add this to my Text_ExceptionLogging
function too, but I think that logging the exception’s message would be useful in general for everyone. I can see it in the console, in the log stream, so why wouldn’t it be available in AI too?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
No. This issues was created before isolated function app was even announced or .NET 5 was released. I’ve never used the isolated concept.
Hello, is this a C# .NET isolated function app? If so, this is a known issue - we are currently working on a fix. https://github.com/Azure/azure-functions-host/pull/8314