question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Add overload of AddAzureClientsCore that allows enabling logging

See original GitHub issue

Library name and version

Azure.Core 1.25.0

Describe the bug

Azure.Core logs aren’t printed to the console. I’m either missing a step, or this is a bug.

Expected behavior

Azure.Core logs should be printed to the console. I expected to see the HTTP request and response bodies there. Instead, I saw no logs.

Actual behavior

Azure.Core logs aren’t printed to the console.

Reproduction Steps

  1. Create a new ASP.NET Core 6.0 Razor Pages app via the project template in VS 2022.

  2. Add the following code to Program.cs:

    builder.Services.AddAzureClientsCore();
    
  3. In the OnGet method of Index.cshtml.cs, add Azure SDK library client code that initiates an HTTP request. Ensure the options object’s Diagnostics.IsLoggingContentEnabled property is set to true. For example, using v1.1.0 of the Monitor Query library:

                var client = new LogsQueryClient(
                    new DefaultAzureCredential(),
                    new LogsQueryClientOptions
                    {
                        Diagnostics = { IsLoggingContentEnabled = true }
                    });
    
                var startDate = DateTime.Parse("2022-07-12 00:00:00");
                var endDate = DateTime.Parse("2022-07-14 23:59:59");
                var metricType = "HeartbeatState";
                var metricNamespace = "netstandard2.0";
    
                var query = $"AppMetrics | where Name == '{metricType}' and Properties has '{metricNamespace}'";
                Response<LogsQueryResult> response = await client.QueryWorkspaceAsync(
                    "<log_analytics_workspace_id>", query, new QueryTimeRange(startDate, endDate));
    
                LogsTable table = response.Value.Table;
                Console.WriteLine(table.Rows.Count);
    
  4. In appsettings.Development.json, add the following inside of Logging:LogLevel:

    "Azure.Core": "Debug",
    
  5. Run the app using the default launch profile in VS 2022.

Environment

VS info:

Microsoft Visual Studio Enterprise 2022 Version 17.3.0 Preview 4.0 VisualStudio.17.Preview/17.3.0-pre.4.0+32714.290 Microsoft .NET Framework Version 4.8.04161

Installed Version: Enterprise

dotnet --info output:

.NET SDK (reflecting any global.json):ddie/app-insights-query]> do Version: 6.0.302 Commit: c857713418

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.302\

global.json file: C:\git\Azure\azure-sdk-for-net\global.json

Host: Version: 6.0.7 Architecture: x64 Commit: 0ec02c8c96

.NET SDKs installed: 2.1.818 [C:\Program Files\dotnet\sdk] 3.1.421 [C:\Program Files\dotnet\sdk] 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.302 [C:\Program Files\dotnet\sdk] 6.0.400-preview.22330.6 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
scottaddiecommented, Jul 29, 2022

The team discussed this issue offline. We decided to:

  • Update the XML docs for the existing AddAzureClientsCore extension method. State that log forwarding won’t be started.
  • Add a new AddAzureClientsCore method overload. The overload will accept a bool indicating whether log forwarding should be started.
1reaction
scottaddiecommented, Jul 26, 2022

Adding those 2 lines to start the log forwarder does solve the problem for me. And yes, I agree we should make this fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CHANGELOG.md - azure-sdk
Features Added. Added the AddAzureClientsCore method overload that has a parameter to allow enabling log forwarding to ILogger .
Read more >
Azure SDK for .NET (August 2022)
Added the AddAzureClientsCore method overload that has a parameter to allow enabling log forwarding to ILogger . Form Recognizer 4.0.0-beta.5 Changelog.
Read more >
Azure SDK for .NET (September 2022)
Added the AddAzureClientsCore method overload that has a parameter to allow enabling log forwarding to ILogger . Form Recognizer 4.0.0 Changelog. Breaking ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found