Reputation: 4594
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.
Upvotes: 6
Views: 778
Reputation: 4594
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.
Upvotes: 6