I have an asp.net core deployed to azure, and I am trying to configure logging to my application using the Microsoft.Extentions.Logging
interfaces.
curr
First of all you have to configure logs in your application on Azure:
There is also an option to look at the application console output:
You can also configure Storage on Azure and save logs there (you can configure that in Diagnostic logs section).
If you want to use the Log Stream in an easy way in Azure, you can do this:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
var sourceSwitch = new SourceSwitch("DefaultSourceSwitch");
sourceSwitch.Level = SourceLevels.Information;
loggerFactory.AddTraceSource(sourceSwitch, new TextWriterTraceListener(writer: Console.Out));
}
TraceListener will ensure that your logs will go to the standard trace output.
You also need to enable stdoutLogEnabled
in the web.config
(set it to true).
<aspNetCore stdoutLogEnabled="true" />
If you do these two things, you will see all your logs and system logs as well in the LogStream. You can control the level yourself.
P.S. This will work only on Full .NET Framework
P.P.S. I think if you turn on logging to blob under Diagnostic logs
setting in Azure, you can have it saved to blob. So everything will happen without you writing any code and manually writing to some location.