'How to send logs to blob storage after setting up Azure app service log?

I have followed the documentation and this is my code

 public class omeController : Controller
    {
        private readonly ILogger<omeController> _logger;

        public omeController(ILogger<omeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            
            _logger.LogError("This is error logging in Index");
            
            return View();
        }

        public IActionResult Privacy()
        {
            _logger.LogInformation("Welcome to Privacy");
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            _logger.LogInformation("Error occured");
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

In my code, I have purposefully omitted 'H' from 'HomeController', while after publishing it I am receiving the error page on chorome still no log is being entered in my blob storage even after configuring the setting. I have uploaded the screenshot of my App Service Log and Log folder inside Blob storage.

I am currently working on .Net 6 and my Program.cs looks like this

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

//This single line of code below is added my me
builder.Logging.AddAzureWebAppDiagnostics();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // 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.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();



Solution 1:[1]

We have tried the same on our environment with .net6 application and can able to see the logs in Log Stream and stored in blob storage as well.

  • Created ASP.NET core application and published to Azure . enter image description here

  • Enabled the below settings for logs and to store in blob in our Application. enter image description here

  • After sometime we will be able to see the logs in our Container as below:

enter image description here

NOTE: Please make sure that after enabled we have the following configuration in Azure App service.

DIAGNOSTICS_AZUREBLOBCONTAINERSASURL

enter image description here

For more information please refer this BLOG:- Configuring Logging in Azure App Services

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AjayKumarGhose-MT