ASP.NET Core Web API with Google Cloud

Vivek Barnwal 71 Reputation points
2025-07-21T11:00:35.8966667+00:00

Hello Developer's,

I'm builded a .NET Core Web API using .NET 8.

And I'm interested to use Google Cloud Operation Suite for Logs Monitoring and Logging Purposes.

Is there any references which I can follow and suggestions how to integrate .NET Core with Google Operation Suite?

Thanks,

Vivek!

Developer technologies | ASP.NET | ASP.NET API
0 comments No comments
{count} votes

Answer accepted by question author
  1. Danny Nguyen (WICLOUD CORPORATION) 3,500 Reputation points Microsoft External Staff
    2025-07-22T08:50:21.0366667+00:00

    Hi Vivek,

    I see that you are looking for ways to integrate ASP.NET Core Web API application with  Google Cloud Operations Suite for Logging purposes.

    From what I've researched, a decent starting place would be here: https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore3/latest

    Google.Cloud.Diagnostics.AspNetCore3 is an ASP.NET Core instrumentation library for Google Logging, Error Reporting and Tracing. It allows for simple integration of Google observability components into ASP.NET Core 3.1+ applications with minimal custom code.   Note: ASP.NET Core 3.1 is the long-term support release of ASP.NET Core 3.x.

    Since you're using .NET 8, this library is perfect for your needs.

    Core Integration Guides:


    In summary, here's what you need:

    1. Install Required NuGet Packages

     # Main integration package
    dotnet add package Google.Cloud.Diagnostics.AspNetCore3
    
    # Optional: Direct API access
    dotnet add package Google.Cloud.Logging.V2
    
    # Optional: Custom metrics
    dotnet add package Google.Cloud.Monitoring.V3
    

    2. Configure Services in Program.cs

    // Add Google Cloud diagnostics
    builder.Services.AddGoogleDiagnosticsForAspNetCore();
    
    var app = builder.Build();
    
    

    3. Set Up Authentication

    Set up Google Cloud credentials via service account or default credentials:

    Step 1: Create Service Account

    Official documentation reference: Getting started with authentication guide Authentication methods at Google | Google Cloud

    1. Go to Google Cloud Console: https://console.cloud.google.com/iam-admin/serviceaccounts
    2. Create Service Account: Click "Create Service Account"
    3. Assign Required Roles:
      • Logging Admin (for Cloud Logging)
        • Monitoring Metric Writer (for Cloud Monitoring)
          • Cloud Trace Agent (for distributed tracing)
            • Error Reporting Writer (for error reporting)

    Step 2: Download Key File

    1. Generate Key: Click on your service account → "Keys" tab → "Add Key" → "Create New Key"
    2. Choose JSON format and download the file
    3. Store securely: Place the JSON file in a secure location on your system

    Step 3: Set Environment Variable

    Official method: Set the environment variable GOOGLE_APPLICATION_CREDENTIALS. This variable applies only to your current shell session Authentication methods at Google | Google Cloud

    Windows:

    set GOOGLE_APPLICATION_CREDENTIALS=C:\path\to\your\service-account-key.json
    

    macOS/Linux:

    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"
    

    4. Enable Components

    (these are covered well in Google Cloud Observability document https://cloud.google.com/dotnet/docs/stackdriver))


    Additional Resources


     Hope this helps you out, please reach out if you need any help.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.