Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log stream does not pick up messages

In ASP.NET Core application I added the following to the controller action

System.Diagnostics.Trace.WriteLine("Wrote log at " + DateTime.Now.ToLongTimeString());
System.Diagnostics.Trace.TraceError("Wrote error log at " + DateTime.Now.ToLongTimeString());
System.Diagnostics.Trace.TraceInformation("Wrote info log at " + DateTime.Now.ToLongTimeString());

I enabled Application Logging (Filesystem) under Diagnostic Logs menu in Azure, but under Log Stream I do not see any of my trace messages. Am I missing something?

Update

I created a sample MVC application using the .NET Framework (instead of .NET Core) and Log Stream works fine when I use System.Diagnostics.Trace to output messages.

Does this mean I cannot use System.Diagnostics.Trace in .NET Core to output messages to Log Stream? This works in Visual Studio to output messages to Output window.

like image 269
nomad Avatar asked May 14 '18 15:05

nomad


1 Answers

As per Logging in ASP.NET Core

Navigate to the Log Streaming page to view application messages. They're logged by application through the ILogger interface.

In the ASP.NET Core app I injected the logger in the Controller:

private readonly ILogger _logger;
public HomeController(ILogger<HomeController> logger)
{
    _logger = logger;
}

And now can use it in Controller actions.

_logger.LogWarning(100, "Warning using ILogger");

And now these logs show up on Log Streaming page in Azure web app.

like image 58
nomad Avatar answered Oct 31 '22 13:10

nomad