Problems I had with LogAnalytics

Ok so this is something that I was not really aware on how to do. The assignment was to read the data from the log analytics in azure to show it in one of our application by using c#

The challenge was to understand how to do it. So I started searching google and I found these three very interesting links

https://dev.loganalytics.io/documentation/Tools/CSharp-Sdk

this link is mentioned on these SDKs but it limited to limitations in the OpenAPISpecification. I am going to try that out to see if it works or not. I couldn’t quite understand the domain in this part may be its super easy and obvious but as I said I am not fully aware I think I will skip that,

The other way that I found is mentioned on this link

https://docs.microsoft.com/en-us/rest/api/loganalytics/query/get

this is the more direct way of accessing it but its more to access via power shell or python. There is still no way mentioned here to access it via c# so I found these two links

https://stackoverflow.com/questions/53915236/querying-azure-log-analytics-from-c-sharp-application

https://blogs.technet.microsoft.com/livedevopsinjapan/2017/08/23/log-analytics-log-search-rest-api-for-c/

from the second link I was able to get the bearer token so I use this link to get the token and from the first link I checked how to use the api call.

Initially I was still getting the 443 forbidden so what I did is I created a new app and allowed the log analytics access to that app. I did another run and it still didn’t work. So then I realized that my log analytics workspace should also that app to access the logs. So I have to add the role assignment in the workspace for that app. I did that and after that I got a 404 because the log table that I accessed doesn’t exists so I added another table name ‘Usage’ in the query and it worked fine.