Using .NET logging frameworks or calling the API

There are several ways to use Cloud Logging from your .NET application:

Use a Google logging provider for .NET's standard logging framework

You can enable Cloud Logging for .NET applications by using theGoogle.Cloud.Diagnostics libraries for .NET.

Use a Google Log4Net provider

TheGoogle.Cloud.Logging.Log4Net library implements a Log4Net provider forCloud Logging. For examples that show how to configure and usethis library, see theGoogle.Cloud.Logging.Log4Net documentation.

UseGoogle.Cloud.Logging.V2 to directly call the Logging API

You can also write logs by calling the Cloud Logging API usingtheGoogle.Cloud.Logging.V2 client library. You can install this library fromNuGet.

After theGoogle.Cloud.Logging.V2 client library is installed, you canstart sending your application's logs to Cloud Logging. For example, youmight customize the following method and add it to your application code.To view the full sample, clickMore,and then selectView on GitHub.

privatevoidWriteLogEntry(stringlogId){varclient=LoggingServiceV2Client.Create();LogNamelogName=newLogName(s_projectId,logId);varjsonPayload=newStruct(){Fields={{"name",Value.ForString("King Arthur")},{"quest",Value.ForString("Find the Holy Grail")},{"favorite_color",Value.ForString("Blue")}}};LogEntrylogEntry=newLogEntry{LogNameAsLogName=logName,Severity=LogSeverity.Info,JsonPayload=jsonPayload};MonitoredResourceresource=newMonitoredResource{Type="global"};IDictionary<string,string>entryLabels=newDictionary<string,string>{{"size","large"},{"color","blue"}};client.WriteLogEntries(logName,resource,entryLabels,new[]{logEntry},_retryAWhile);Console.WriteLine($"Created log entry in log-id: {logId}.");}

Write some logging code that callsWriteLogEntry(). The resulting log entrywill be in the Logs Explorer under theGlobal resource.

In the Google Cloud console, go to theLogs Explorer page:

Go toLogs Explorer

If you use the search bar to find this page, then select the result whose subheading isLogging.

Resources

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.