I have uploaded a very simple app in Azure on .NET Core 2.1.3.
Configured the App Service logging as follows:
the code:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
public class Startup
{
private readonly ILogger<Startup> logger;
public Startup(IConfiguration configuration, ILogger<Startup> logger)
{
this.Configuration = configuration;
this.logger = logger;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Commented lines doesn't affect ...
//loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
// loggerFactory.AddDebug();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
loggerFactory.AddAzureWebAppDiagnostics();
this.logger.LogInformation("Loading::::::::::::::::::");
app.Run(async (context) =>
{
this.logger.LogInformation("OnRequest::::::::::::::::::");
await context.Response.WriteAsync("Loading...");
});
}
}
The problem is that the logging works locally, but no in azure. If I open /Log Files/Application/afg4322-201809062011.log
my messages OnRequest::::::::::::::::::
and Loading::::::::::::::::::
didn't appear there. Currently the logic catches all requests and simply writes a log message.
Also I've installed Microsoft.Extensions.Logging.AzureAppServices
and troubleshot https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.1#aspnet-core-module-stdout-log nothing working.
How to log a message in Azure app ? Maybe I'm missing some simple setting?
The applicationSettings.json
:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"Console": {
"IncludeScopes": "true"
}
}
}
I've checked this articles - Asp.net Core azure web app logging - How to enable Application Logs in Azure for Net Core 2 App?
I'm trying to avoid suggestion from Ilya Chernomordik
where he says to set <aspNetCore stdoutLogEnabled="true" />
and modify SourceSwitch
. I think it's not the correct solution.