Search code examples
c#asp.net-coregoogle-cloud-rungoogle-cloud-logging

ASP.NET Core 6 app on Cloud Run not routing logs to Cloud Logging


My ASP.NET Core 6.0 website running in a container on Cloud Run is configured to log to Google Cloud Logging by way of a call to AddGoogleDiagnosticsForAspNetCore(...).

This works for my production Cloud Run website but not for dev-test. Both service accounts have the Logs Writer role.


Solution

  • The fault was mine. And yes, the question was unhelpful, though in fairness there aren't many moving parts to the problem*.

    My code was negating the production check. I failed to spot the ! and was distracted by the fact that it works in production, and that when it originally didn't work in production it was because of IAM permissions.

    It possibly works in production because a) the deployed code is older, different b) something about its configuration is enabling the console logger.

            if (!this.HostingEnvironment.IsProductionLike())
            {
                AddGoogleDiagnostics(services);
            }
    

    Finding the fault involved adding a controller action to get and return an ILoggerProvider from the IServiceProvider which was null when called by curl, causing me to look again at the code which was supposed to register this type, the code above.

    In conclusion: not many moving parts = probably developer error.

    *I have this idea that if everyone always posted all their problems and then the solutions, however dumb it makes them appear, we'd have a great resource. Most of my stack rep comes from answering my own questions.