Luke Puplett
Luke Puplett

Reputation: 45095

How can I see or filter traces for the logger name in Azure Application Insights?

When an ILogger is initialised, we give it a name which is often the type name. When logs are written through it this value is clearly printed to the console. Also, the severity filtering in config works via this name.

However, I can't seem to see the name in Application Insights / Log Analytics. It logs a slew of stuff I don't care about but seems to miss out this primary field.

Thanks

Ivan asked for code and screenies, so here's standard code we've all been using for years to make a named logger.

var logger = loggerFactory.CreateLogger("EventHub");
logger.LogInformation($"Publishing event '{eventName}' from '{sourceId}'.");

And here are all the fields available in Logs (Analytics) in the portal. None of these are the logger name. It just seems to me that the name of the logger would be in the top five most useful fields.

Log Analytics fields

Thanks again.

Upvotes: 3

Views: 11588

Answers (2)

TaeKasidit
TaeKasidit

Reputation: 62

I just want to add that Azure portal uses the Kusto query language for making complex queries. You can find the document about usage and syntax here.

https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/

Upvotes: -1

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

The columns in the table(in your case, it's traces table) are fixed.

When you use this line of code loggerFactory.CreateLogger("EventHub");, the "EventHub" actually becomes a property of the customDimensions column. So you can use this property of EventHub to filter your log data.

Here is my test with your code:

var logger = loggerFactory.CreateLogger("EventHub");
logger.LogInformation($"Publishing event '{eventName}' from '{sourceId}'.");

Then in azure portal -> your application insights -> Logs(Analytics), query the logs, and you can see the eventHub is a property of customDimensions:

enter image description here

How to filter logs via the property of eventHub:

Use this query:

traces 
| where customDimensions.CategoryName == "eventHub"

then all the matched records are fetched:

enter image description here

Upvotes: 9

Related Questions