[Feature Request] Add overload of AddAzureClientsCore that allows enabling logging
See original GitHub issueLibrary 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
-
Create a new ASP.NET Core 6.0 Razor Pages app via the project template in VS 2022.
-
Add the following code to Program.cs:
builder.Services.AddAzureClientsCore();
-
In the
OnGet
method of Index.cshtml.cs, add Azure SDK library client code that initiates an HTTP request. Ensure the options object’sDiagnostics.IsLoggingContentEnabled
property is set totrue
. 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);
-
In appsettings.Development.json, add the following inside of
Logging:LogLevel
:"Azure.Core": "Debug",
-
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:
- Created a year ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
The team discussed this issue offline. We decided to:
AddAzureClientsCore
extension method. State that log forwarding won’t be started.AddAzureClientsCore
method overload. The overload will accept a bool indicating whether log forwarding should be started.Adding those 2 lines to start the log forwarder does solve the problem for me. And yes, I agree we should make this fix.