With the help of forum and research I am able to view the logfile for the errors occur in hosted ASP.NET Core 6 Web API. So when the error occurred, I captured that under _logger.LogError("error)
.
But I also implemented _logger.LogInformation("information")
. I do want to see this regardless of error. After the implementation, I do not see the information logs.
Please see the below configurations:
Program
file:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://*:5001").
ConfigureLogging(logging => { logging.AddAzureWebAppDiagnostics(); })
.ConfigureServices(services=>
{
services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "my-azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
});
})
.UseStartup<Startup>();
AppSettings.json
:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning"
}
},
As you are working with
ASP.NET Core 6
we can configure the middleware directly inProgram.cs
file.As mentioned earlier in my previous answer, I have used the same code to log traces in a file.
My
Program.cs
file:My
.csproj
file:Application Logging
settings fromApp Service logs
.*** Log stream:***
In file (
C:\home\LogFiles\Application
):