dotnet / dotnet/aspnetcore

No logs for System.NET

Open
#50,041 14 comments 0 reactions 0 assignees View on GitHub
area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

.NET Core 6
I am trying to write a trace to my console for all System.Net calls (executed via HttpClient).
I'm getting nothing from that namespace. I am seeing console logs from other namespaces.

This is in my appsettings.json

```JSON
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "None",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net": "Trace"
},
"Console": {
"IncludeScopes": true,
"LogLevel": {
"Microsoft": "None",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net": "Trace"
}
}
},
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://*:5001",
"Certificate": {
"Path": "c:\\1\\cert.pem",
"KeyPath": "c:\\1\\key.pem",
"AllowInvalid": true
}
}
}
},
"AllowedHosts": "*",
}
```

### Expected Behavior

See Trace logs for System.Net in my console.

### Steps To Reproduce

Have the appsettings.json mentioned.

Make an http request using HttpClient;

Have this in program.cs:

```
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders(); // Clear any default providers (optional)
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole(); // Add console logging
})
.ConfigureWebHostDefaults(webBuilder =>
{
var config = new ConfigurationBuilder().AddJsonFile($"appsettings.json", optional: true).Build();

webBuilder.UseConfiguration(config);

webBuilder.UseStartup();
});
```

### Exceptions (if any)

_No response_

### .NET Version

7.0.202 however project file has `net6.0`

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the missing System.Net output using the appsettings.json and Program.cs shown in the issue, with an HttpClient request. Check whether the configured logging categories are reaching the console provider and compare the result with the expected System.Net trace logs. Done means identifying and documenting a reproducible fix or confirmed framework limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.