简体   繁体   中英

Structured logging in an Azure Function v3 with Azure Log Analytics

I'm trying to use structured logging by logging in my Azure Function like this:

log.LogError("Failed to get object. ({customerId}, {objectId}, {errorMessage})", request.CustomerId,
                    request.ObjectId, errorMessage);

My Azure Function is plugged in to a Log Analytics workspace through Diagnostic settings.

Is there a way to extract the customerId, objectId and errorMessage from the Message ?

I would like to create for example a dashboard showing the number of errors per customerId.

I've tried to "Extract Fields" functionality to no avail. Do I need to use Application Insights and custom Dimensions ?

You are almost already in the right path. With the example log statement you shared above, you should already see customerId, objectId, errorMessage in the customDimentions of Application Insights log if you have enabled built-in App Insights Integration . That's the exact reason, Loging in .net core is built this way for templating. You can also find details in Azure Function structured logging . 在此处输入图片说明

But you mentioned you are using Log Analytics workspace through Diagnostic settings which I don't think has support for structured logging yet (and it's in preview currently, so might change in future). 在此处输入图片说明

So, Application Insights would be the way to go for you. You can anyway query app insights from Log Analytics too apart from inbuilt query pane of App Insights.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM