2
votes

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.

currently my app is writing the logs to Log Files folder in the web app storage.

enter image description here

This seems like the right place to log my changes. However, I want to view these logs in a normal interface - downloading a text file everytime, is kinda annoying.

I have looked into application insights, and azure diagnostic logs, but none of them suggest how to work with it using the ILogger interface.

2

2 Answers

2
votes

First of all you have to configure logs in your application on Azure: Logs

There is also an option to look at the application console output:

Output

You can also configure Storage on Azure and save logs there (you can configure that in Diagnostic logs section).

2
votes

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.