Reputation: 45095
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.
Thanks again.
Upvotes: 3
Views: 11588
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
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:
How to filter logs via the property of eventHub:
Use this query:
traces
| where customDimensions.CategoryName == "eventHub"
then all the matched records are fetched:
Upvotes: 9