共用方式為


Searching Log Analytics using Azure SDK with New Simpler Library "Fluent"

I wrote this post on this blog. I thought that We didn't have the Azure SDK for Log Analytics. However, I was wrong.

They have. It is great one.

Only problem is the documentation and sample code is not shown until now.  So I wrote a sample code for it. Also the code becomes very simple than used to. I realize they use brand new API for the Log Analytics code. Let's enjoy it.

Simpler Azure Management API "Fluent"

The new API's namespace is "Fluent". It seems preview.

https://azure.microsoft.com/en-us/blog/simpler-azure-management-libraries-for-net/

 

We are announcing the first developer preview release of the new, simplified Azure management libraries for .NET. Our goal is to improve the developer experience by providing a higher-level, object-oriented API, optimized for readability and writability. 

Using the new API, we can easily write the code to operate Azure. Especially, Token management.

All you need is just three lines. This is the example of the Service Principle constructor.

  var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
 var client = new OperationalInsightsManagementClient(credentials);
 client.SubscriptionId = subscriptionId;

Now you can get a client.  Then operate it.

  var parameters = new SearchParameters();
 parameters.Query = "*";
 parameters.Top = top;
 var searchResult = await client.Workspaces.GetSearchResultsAsync(resourceGroup, workspeceName, parameters);

Then you can get the result. You can Unmarshal it if you like.

  foreach (var result in searchResult.Value)
 {
 Console.WriteLine(result.ToString());
 }

Compared with the old one, you will find it is very simple.

Resource

You can find whole source code on my GitHub.

List of the OMS resource

Old Post for Log Analytics (Let's compare with new one)

Announcement of the New API fluent.

OMS Azure SDK for .NET. I recommend to read Test code for understanding the behavior

Azure SDK for .NET Fluent branch. You can see the document and sample code in it. (Unfortunately, we can't find LogAnaytics sample and Service Principle sample)

 

Enjoy