question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log the exception's message to Application Insights

See original GitHub issue

I’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:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kleniumcommented, Jun 15, 2022

No. This issues was created before isolated function app was even announced or .NET 5 was released. I’ve never used the isolated concept.

0reactions
madelinegordoncommented, Jun 15, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnose exceptions in web apps with Application Insights
Open the app solution in Visual Studio. Run the app, either on your server or on your development machine by using F5 ....
Read more >
Application Insights - Logging exceptions
I wrote a custom logger for Application Insights in my app. I don't see any exceptions or ANY events when viewing App Insights...
Read more >
How to send an “exception” to Application Insights in .NET?
LogError you will see your error as a trace in Application Insights. For example: logger.LogError("$"Object not found with id {objectId}");.
Read more >
Using Azure Application Insights For Exception Logging In ...
Click the LogsAppInsights and in the menu bar, you can find the Logs option under the Monitoring section, click on the Logs option...
Read more >
Working with Azure Application Insights for Exception Logging
Learn how to use Azure Application Insights for exception logging in your custom developed solutions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found