Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.36k stars 4.79k forks source link

Creating a Diagnostic Setting to a FunctionApp to log to a Log Analytics Workspace #35240

Closed richaplinvs closed 10 months ago

richaplinvs commented 1 year ago

Library name and version

Azure.ResourceManager.AppService 1.0.01, Azure.ResourceManager 1.4.0

Query/Question

I want to configure the FunctionApp to log to a Log Analytics Workspace using the Diagnostic Setting. However I can't see how to do this with the Azure.ResourceManager api.

I have created a function using the following code:

var webSiteData = new WebSiteData(location);
webSiteData.Kind = "functionapp";
var funcResponse = await resourceGroup.GetWebSites().CreateOrUpdateAsync(WaitUntil.Completed, functionName, webSiteData);
var funcResource = funcResponse.Value;

There's a GetSiteDiagnostics() but no equivalent Update method. There's very limited samples for this API and even looking through the source code is hard as the comments are all autogenerated seem to restate class/method names - is there some other resource that would help?

Any help would be appreciated!

Environment

.Net runtime Visual Studio for Mac.

jsquire commented 1 year ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

melina5656 commented 11 months ago

Hi @richaplinvs Thank you for using Azure SDK for .NET. It seems like you are looking at a wrong package. The correct package would be:Azure.ResourceManager.Monitor The code sample you may refer:

     //Create a Diagnostic Setting
     var scope = appServicePlan.Id;
     var dsname = "ds1";
     var diagnostSettingCollection = client.GetDiagnosticSettings(scope);
     var diagnostSettingData = new DiagnosticSettingData()
     {
         WorkspaceId = new ResourceIdentifier(workspace.Id),
         StorageAccountId = new ResourceIdentifier(storageAccount.Id),
         Metrics =
         {
             new MetricSettings(true)
             {
                 Category = "AllMetrics",
             }
         }
     };
     var diagnost = await diagnostSettingCollection.CreateOrUpdateAsync(WaitUntil.Completed, dsname, diagnostSettingData);
     Console.WriteLine(diagnost.Value.Data.Id);
github-actions[bot] commented 11 months ago

Hi @richaplinvs. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] commented 10 months ago

Hi @richaplinvs, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.