I've already tried using System.Diagnostics.Debug.WriteLine as suggested here, but nothing is written to console when I put a WriteLine call at the top of my Startup.ConfigureServices method then run the ASP.NET application locally with dotnet run -c debug.
For other reasons I can't just use the ILogger interface (trying to debug logging some Application Insights initializers so can't get an ILogger instance).
Using .NET Core 3.1.201. Steps to reproduce:
- Open console, move to empty directory and type
dotnet new web - Open generated project, add
System.Diagnostics.Debug.WriteLine("TEST TEST TEST");to theStartup.ConfigureServicesmethod - Open the
appsettings.development.jsonfile and set all log levels toDebug - Run
dotnet run -c debugand view console output; there will be noTEST TEST TESTstring present:
PS C:\Users\ahelwer\source\prototype\test> dotnet run -c debug
dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
Hosting starting
dbug: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[2]
Failed to locate the development https certificate at '(null)'.
dbug: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[0]
Using development certificate: CN=localhost (Thumbprint: 9C942CB86D28BD34EC038AC614E1D069646F30E7)
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
dbug: Microsoft.AspNetCore.Hosting.Diagnostics[0]
Loaded hosting startup assembly test
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\ahelwer\source\prototype\test
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
Hosting started
Contents of appsettings.development.json:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Debug",
"Microsoft.Hosting.Lifetime": "Debug"
}
}
}