Reputation: 77
I am trying to use Trace Logging in Azure with a Asp.Net Core 2 API. I have an AppService and have gone to the Diagnostics Logs section and enabled Applicationo Logging (Blob) and as per this documentation that should be all I need to do? I have made the following endpoints to test this:
[AllowAnonymous]
[Route("api/TraceWarning")]
public async Task<IActionResult> TraceWarning()
{
Trace.TraceWarning("This is a TraceWarning Message");
return Ok();
}
[AllowAnonymous]
[Route("api/TraceError")]
public async Task<IActionResult> TraceError()
{
Trace.TraceError("This is a TraceError Message");
return Ok();
}
[AllowAnonymous]
[Route("api/ThrowError")]
public async Task<IActionResult> ThrowError()
{
throw new Exception("THROW ERROR");
return Ok();
}
The application logs show the end points getting hit, and show the stack trace for the error, that's great but I'm not getting the messages.
I've tried a lot of different stuff from different searches/guides, but just can't seem to get it to work.
My only conclusion is that I must be missing config of some kind somewhere. Such as, do I need to change my web config (the docs don't say to but I've seen that elsewhere)? What should the LogLevel be in my appsettings.json? Am I forced to fully integrate with Application Isights (and how would I do that)? Would there need to be other code beyond just writing the trace that I need to include at startup?
Thank you for any help, this kind of has me at the end of my ropes.
Upvotes: 1
Views: 687
Reputation: 20127
Application diagnostics allows you to capture information produced by a web application. ASP.NET applications can use the System.Diagnostics.Trace class to log information to the application diagnostics log.
The documentation you provided is supporting .net web app to use System.Diagnostics.Trace
to log information.
If you are using a Asp.net Core 2 API, ASP.NET Core new project templates already setup some basic logging providers with this code in the Startup.Configure method:
loggerFactory.AddConsole();
loggerFactory.AddDebug();
For more details, you could refer to this article and this one.
Upvotes: 1