1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the kind of oversight that makes you want to cry lol, ty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.