An application in .NET 6 has been created by me. (web app with react)
In appsettings.json
I have:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
I tried to log some message
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
_logger.LogInformation("test");
}
However, I couldn't find the log file in bin/debug/.net6
Program.cs:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html"); ;
app.Run();
CodePudding user response:
By default, there is no logger that logs to a file. If you want that behaviour, you will need to explicitly add it (e.g. by using something like Serilog). The default logger logs to the console, so you should be able to see your log message there.
This MSDN page has more info on what the default loggers are, and where the log output goes to.