Skip to content

Instantly share code, notes, and snippets.

@taylorhutchison
Last active April 27, 2022 13:51
Show Gist options
  • Save taylorhutchison/98491fdd96a6dcf51ae050b054feebca to your computer and use it in GitHub Desktop.
Save taylorhutchison/98491fdd96a6dcf51ae050b054feebca to your computer and use it in GitHub Desktop.
Writing to the log stream in a Window Azure App Service.
// This is a ASP.NET 6 sample showing how to write to the log stream in a Window Azure App Service.
// It seems standard out (stdout) is disabled in a Window Azure App Service.
// The key for me was adding the Microsoft.Extensions.Logging.AzureAppServices package
// To see logs in the Log Stream
// 1. go to "App Service logs" panel under monitoring
// 2. turn on Application logging (Filesystem)
// 3. set the level to Verbose or whatever is appropriate for the level of logging you want to see.
// Note: This will automatically turn back off after 12 hours by design.
// 4. Now you can see the logs in the Log Stream panel of your App Service.
var builder = WebApplication.CreateBuilder(args);
// You need to add the Microsoft.Extensions.Logging.AzureAppServices packge
// dotnet add package Microsoft.Extensions.Logging.AzureAppServices
builder.Logging.AddAzureWebAppDiagnostics();
var app = builder.Build();
app.MapGet("/", () => {
var logger = app.Services.GetService<ILogger<Program>>();
logger?.LogInformation("This is visible in the Log Stream.");
return "Hello world";
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment