6

I've enabled application logging to a blob for an app service on Azure.

  • I can view the logs in the log stream from the Azure portal
  • I can see that a file like xxxxx-#####.applicationLog.csv is being created each hour in the Azure storage account I created, but this file doesn't actually contain the my application logs
  • I tried enabling Web Server logging to storage on the same account, and that did work - I could see the logs for HTTP requests in a different file
  • I tried creating a new storage account and pointing to it for the logs, but it didn't change anything

Configuration details:

  • The app uses ASP.NET Core 2, running on .NET Framework 4.6.1
  • I configure logging in Program.cs via: .ConfigureLogging(log => log.AddAzureWebAppDiagnostics()) (which is apparently necessary when running on .NET Framework instead of .NET Core runtime)

In summary: No files containing my application logs are created in Azure Storage when I configure it that way in the Azure portal.

6
  • 1
    See: learn.microsoft.com/en-us/azure/app-service/…. Make sure you've followed all the steps there. In particular pay attention to the logging level you've set. The default is "Information", so if you've been logging "Debug", then none of that is going to actually get logged. Commented Oct 27, 2017 at 14:20
  • The logging level is set to verbose. Commented Oct 27, 2017 at 14:27
  • How are you actually logging in your application? Commented Oct 27, 2017 at 14:30
  • Using Microsoft.Extensions.Logging; i.e. injecting ILogger<Type> Commented Oct 27, 2017 at 14:32
  • Is your app running in Azure as well or locally? Commented Oct 27, 2017 at 14:39

1 Answer 1

3

If we want to write Application logs to Azure blob storage ,firstly we need to enable Application log and configure blob storage for it on the Azure portal.

enter image description here

We could following the blog to set up logging in the Asp.net core app.

setting up logging in an ASP.NET Core app doesn’t require much code. ASP.NET Core new project templates already setup some basic logging providers with this code in the Startup.Configure method:

loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
loggerFactory.AddDebug();

I also do demo for it. It works correctly on my side.

1.In the Sartup.cs file add the following code

 loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddAzureWebAppDiagnostics(
                new AzureAppServicesDiagnosticsSettings
                {
                    OutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} [{Level}] {RequestId}-{SourceContext}: {Message}{NewLine}{Exception}",

                }
            );

2.add following code in the HomeController.cs

 private readonly ILogger _logger;
 public HomeController(ILoggerFactory loggerFactory)
 {
     _logger = loggerFactory.CreateLogger<HomeController>();
 }

 public IActionResult Index()
 {
    _logger.LogInformation("Log information");
    _logger.LogError("Logger error");
    return View();
 }

enter image description here

3.Visit the home/index page and check it from the Azure storage blob. Last section of log blob name. Defaults to "applicationLog.txt". We also could set it ourselves.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

It seems like the issue was that I was calling AddAzureWebAppDiagnostics() in Program.cs instead of Startup.cs. Not sure why this project didn't work in that configuration since I have other .Net Core 2 App Services setup that way, but oh well. Thanks!
@Zout can the logs be saved to a csv not a txt ? in other words can the logs be saved in a block blob not append blob?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.