In the ASP.NET Core 2.0, I use the default logging API. My app is hosted as an Azure Web App.
My question: Where are these outputted? And how do I modify it?
(I don't need them in my database or file system for now, just read the recent logs for some debugging).
WHAT I AM DOING:
In my Startup.cs
file I have injected the logging:
private readonly ILogger<Startup> _logger;
public Startup(IConfiguration configuration, ILogger<Startup> logger)
{
_logger = logger;
Configuration = configuration;
}
And I then write a couple of:
_logger.LogInformation("Configure RUNNING");
However, I haven't been able to find any of these in a log inside FTP/Azure portal.
After playing around for an hour, I got to understand how it plays together in asn ASP.NET Core app.
First of all, i would recommend watching this YouTube video: https://www.youtube.com/watch?v=icwD6xkyrsc .
How to solve it
STEP 1:
Go to your
Startup.cs
class. Inside theConfigure
method, make sure it has the following signature:Mine did not have the
ILoggerFactory
. However, you need to add this one. It's by default injected into the class by ASP.NET Core.STEP 2:
Set up your provider.
I setup the following two:
The AddAzureWebAppDiagnostics comes from the package Ojisah mentioned in his answer.
STEP 3:
Now we can start logging.
Example in my
HomeController
:STEP 4: Make sure your log level matches your expectations
Look at your
appsettings.json
to make sure the warning level matches your expectations:STEP 5: See the logs
In Azure, I have been setting up the
Diagnostics logs
tab, I've set this up so it logs to my blobs:STEP 6:
Now you can download and see the log files which is inside your BLOB.
Example from my log file where we can see the log from my
HomeController
:You need to add providers as mentioned later in https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?tabs=aspnetcore2x :
For azure you can use the Azure App Service provider (https://www.nuget.org/packages/Microsoft.Extensions.Logging.AzureAppServices)